Controlling herding in minority game systems

Resource allocation takes place in various types of real-world complex systems such as urban traffic, social services institutions, economical and ecosystems. Mathematically, the dynamical process of resource allocation can be modeled as minority games. Spontaneous evolution of the resource allocation dynamics, however, often leads to a harmful herding behavior accompanied by strong fluctuations in which a large majority of agents crowd temporarily for a few resources, leaving many others unused. Developing effective control methods to suppress and eliminate herding is an important but open problem. Here we develop a pinning control method, that the fluctuations of the system consist of intrinsic and systematic components allows us to design a control scheme with separated control variables. A striking finding is the universal existence of an optimal pinning fraction to minimize the variance of the system, regardless of the pinning patterns and the network topology. We carry out a generally applicable theory to explain the emergence of optimal pinning and to predict the dependence of the optimal pinning fraction on the network topology. Our work represents a general framework to deal with the broader problem of controlling collective dynamics in complex systems with potential applications in social, economical and political systems.

Scientific RepoRts | 6:20925 | DOI: 10.1038/srep20925 statistical-physics community to cast the MG problem in the general framework of non-equilibrium phase transitions 21,20,41,42 . In the Boolean dynamics, for any agent, detailed information about the other agents that it interacts with is assumed to be available, and the agent responds accordingly 1-9,10-12 . Both approaches can lead to "better than random" performance in resource utilization. However, herding behavior in which many agents take identical action 43 can also take place, which has been extensively studied and recognized as one important factor contributing to the origin of complexity that leads to enhanced fluctuations and, consequently, to significant degradation in efficiency [1][2][3][4][5][6][7][8][9][10][11][12] .
The control scheme we analyze in this paper is the pinning method that has been studied in controlling the collective dynamics, such as synchronization, in complex networks 11,[44][45][46][47][48][49][50] . For the general setting of pinning control, the two key parameters are the "pinning fraction, " the fraction of agents chosen to hold a fixed state, and the "pinning pattern, " the configuration of plus or minus state assigned to the pinned agents. Our previous work 11 treated the special case of two resources of identical capacities, where the pinning pattern was such that the probabilities of agents pinned to positive or negative state (to be defined later) are equal. Note that, while the pinned agents are frozen during system's dynamical evolution, they are different from the "quenched" behavior in MG 23 . Especially, in our case the pinned states are a controlled state by design, but in typical MG dynamics the quenched behaviors are an emergent state through self organization. Here, we investigate a more realistic model setting and articulate a general mathematic control framework. A striking finding is that biased pinning control pattern can lead to an optimal pinning fraction for a variety of network topologies, so that the system efficiency can be improved remarkably. We develop a theoretical analysis based on the mean-field approximation to understand the non-monotonic behavior of the system efficiency about the optimal pinning fraction. We also study the dependence of the optimal fraction on the topological features of the system, such as the average degree and heterogeneity, and obtain a theoretical upper bound of the system efficiency. The theoretical predictions are validated with extensive numerical simulations. Our work represents a general framework to optimally control the collective dynamics in complex MG systems with potential applications in social, economical and political systems.

Results
Boolean dynamics. In the original Boolean system, a population of N agents compete for two alternative resources, denoted as r = + and r = − , which have the same accommodating capacity = = / + − C C N 2. Similar to the MG dynamics, only the agents belonging to the global minority group are rewarded by one unit of payoff. As a result, the profit of the system is equal to the number of agents selecting the resource with attendance less than the accommodating capacity, which constitute the global-minority group. The dynamical variable of the Boolean system is denoted as A t , the number of + agents in the system at time step t. The variance of A t about the capacity + C characterizes the efficiency of the system. The densities of the + and − agents in the whole system are ρ = / + A N t and ρ ρ = − − + 1 , respectively. The state of the system can be conveniently specified by the column vector ρ ρ ρ = ( , ) + − T .
A Boolean system has two states (a binary state system), in which agents make decision according to the local information from immediate neighbors. The neighborhood of an agent is determined by the connecting structure of the underlying network. Each agent receives inputs from its neighboring agents and updates its state according to the Boolean function, a function that generates either + and − from the inputs 3 . Realistically, for any agent, global information about the minority choice from all other agents at the preceding time step may not be available. Under this circumstance, the agent attempts to decide the global minority choice based on neighbors' previous states. To be concrete, we assume 4,11 that agent i with k i neighbors chooses + at time step t + 1 with the probability In this case, rationality demands a stronger preference to the resource + (i.e., with a higher probability). To investigate the issues associated with the control of realistic Boolean dynamics, we define where  is the response function of each agent to its local environment ρ i , i.e., the local neighbor's configuration The quantity ′ F r r (or ) F r r characterizes the contribution of the ′ r -neighbors (or r-neighbors) to the probability for i to adopt r. The quantity F r r represents the strength of assimilation effect among the neighbors, while ′ F r r quantifies the dissimilation effect. Intuitively, the resource with a larger accommodating capacity would have a stronger assimilation effect among agents. By definition, the elements in each column in the matrix  satisfy , i.e., the total probability for an agent to choose + and − is unity.
Using the mean-field assumption that the configuration of neighbors is uniform over the whole system, i.e., The rational response  ( ) of agents to nonidentical accommodation capacities of resources will lead to the , the stable fraction of the agent densities in + and − is simply the ratio of the capacities. The elements of  can then be defined accordingly using this ratio and the condition ≤ ≤ ′ F 0 1 r r , which characterizes a stronger preference to the resource with a larger capacity. For the specific case of identical-capacity resources, we have = + − − + F F , and the solution reduces to the result ρ = ( . , . ) ⁎ 0 5 0 5 T of the original Boolean dynamics 4,11 . The optimal solution for the resource allocation is ρ = + ⁎ ⁎ A N . A general measure of Boolean system's performance is the variance of A t with respect to the capacity + C : which characterizes, over a time interval T , the statistical deviations from the optimal resource utilization 4 . A smaller value of σ 2 indicates that the resource allocation is more optimal. A general phenomenon associated with Boolean dynamics is that, as agents strive to join the minority group, an undesired herding behavior can emerge, as characterized by large oscillations in ( ) A t . Our goal is to understand, for the general setting of nonidentical resource capacities, the effect of pinning control on suppressing/eliminating the herding behavior.
Pinning control scheme. Following the general principle of pinning control of complex dynamical networks 11,44-50 , we set out to control the herding behavior by "pinning" a few agents to freeze their states during the dynamical evolution so as to realize optimal resource allocation for the entire network. Let ρ p be the fraction of agents to be pinned, so the fraction of unpinned (or free) nodes is ρ ρ = − 1 f p . The numbers of the two different types of agents, respectively, are The free agents make choices according to local time-dependent information, for whom the inputs from the pinned agents are fixed.
The two basic quantities characterizing a pinning control scheme are the order of pinning (the way how certain agents are chosen to be pinned) and the pinning pattern 11 . We adopt the degree-preferential pinning (DPP) in which the agents are selected to be pinned according to their connectivity or degrees in the underlying network. In particular, agents of higher degrees are more likely to be pinned. This pinning method originated from the classic control method to mitigate the effects of intentional attacks in complex networks [51][52][53] . The selection of the pinning pattern can be characterized by the fractions η + and η − of the pinned agents that select = + r and = − r , respectively, where η η + = + − 1. The quantities η + and η − are thus the pinning pattern indicators. Different from the previous work 11 that investigated the specific case of η η = = .
+ − 0 5 (half-half pinning pattern), here we consider the more general case where η + is treated as a variable. The pinning schemes are implemented on random networks and scale-free networks with different values of the scaling exponent γ in the power-law degree distribution 54,55 ( ) ∼ γ − P k k . As we will see below, one uniform optimal pinning fraction ρ p exists for various values of the pinning pattern indicator η + .
Simulation Results. To gain insight, we first study the original Boolean dynamics with / = + − C C 1 and  = ( , , ) 0 1; 1 0 for different values of the pinning pattern indicator η + . The game dynamics are implemented on scale-free networks of size = N 1001 and of the scaling exponent γ = .
3 0 54 with the average degree k ranging from 6 to 40. The DPP scheme is performed with pinning fraction ρ p and η + values ranging from 0.6 to 1.0 (i.e., all to + pinning). The variance σ 2 versus ρ p for different values of η + and different degree k are shown in Fig. 1. We see that, in general, systems with larger values of η + exhibit larger variance, implying that a larger deviation of η + from the ratio of the capacity / + C N can lead to lower efficiency in resource allocation. Surprisingly, there exists a universal optimal pinning fraction (denoted by ρ ) ⁎ p about 0.4, where the variance σ 2 is minimized and exhibits an opposite trend for ρ ρ > ⁎ p p , i.e., larger values of η + result in smaller values of σ 2 . The implication is that, deviations of η + from / + C N provide an opportunity to achieve better performance (with smaller variances σ 2 ), due to the non-monotonic behavior of σ 2 with ρ p . To understand the emergence of the optimal pinning fraction ρ ⁎ p , we see from Fig. 1 that the values of ρ ⁎ p are approximately identical for different values of η + , which decrease with the average degree k . As we will see below, in the large degree limit → ∞ k , the value of σ 2 can be predicted theoretically (c.f. Fig. 4).
Simulations using scale-free networks of different degrees of heterogeneity also indicate the existence of the universal optimal pinning control scheme, as can be seen from the behaviors of the variance calculated from scale-free networks of different degree exponents ( Fig. 2) 55 , where smaller values of γ point to a stronger degree of heterogeneity of the system. We see that an optimal value of ρ ⁎ p exists for all cases, which decreases only slightly with γ, i.e., more heterogeneous networks exhibit larger values of the optimal pinning fraction ρ ⁎ p , a phenomenon that can also be predicated theoretically (c.f. Fig. 5).
Scientific RepoRts | 6:20925 | DOI: 10.1038/srep20925 Theoretical Analysis. The phenomenon of the existence of a universal optimal pinning fraction ρ ⁎ p , independent of the specific values of pinning pattern indicator η + , is remarkable. Here we develop a quantitative theory to explain this phenomenon.
To begin, we note that MG is effectively a stochastic dynamical process due to the randomness in the selection of states by the agents. The variance of the system, a measure of the efficiency of the system, is determined by two separated factors. The first, denoted as δ ( ) X 1 , is the intrinsic fluctuations of A about its expected value ⁎ A , defined as δ ≡ ( − ) ⁎ A A 2 , which can be calculated once the stable distribution of attendance ( ) P A is known, where ( ) P A can be obtained either analytically (c.f., Fig. 3) or numerically. The second factor, denoted as ε ( ) X 2 , is the difference of the expected value ⁎ A from the capacity + C of the system: ε ≡ − + ⁎ A C , which also contributes to the variance of the system. Taking into account the two factors, we can write the system variance σ 2 [defined in Eq. (4)] as which is a sum of two factors: In contrast to the special case of = + ⁎ A C treated in previous works 4, 11 , the more general cases are that the expected value ⁎ A is not equal to the capacity + C . Nonzero values of ε are a result of the biased pinning pattern (η ≠ . + 0 5) or improper response to the limited capacities of the resources. In fact, recent studies of the flux-fluctuation law in complex dynamical systems indicated that the variance of the system is determined by the two factors: intrinsic fluctuations and external driving 56-62 . Stable distribution of attendance. To quantify the process of biased pinning control, we derive a discrete-time master equation and then discuss the effect of network topology on control.

Discrete-time master equation for biased pinning control.
To understand the response of the Boolean dynamics to pinning control with varied values of the pinning pattern indicator η + , we generalize our previously developed analysis 11 . Let P p be the probability for a neighbor of one given free agent to be pinned so that the probability of encountering a free agent is = − P P 1 f p . The transition probability of the system from ( ) A t to ( + ) A t 1 can be expressed in terms of η + . In particular, note that the state transition is due to updating of the N f free agents, as the remaining N p agents are fixed. To simplify notations, we set ( ) . The conditional transition probability from i at t to k at t + 1 is 3 0. In each realization, the system evolves for 10000 time steps, and σ 2 is calculated from the corresponding ( ) A t , with the first 3000 time steps discarded to avoid the influence of transient state. 4. In each realization, the system evolves for 10000 time steps, and σ 2 is calculated from the corresponding ( ) A t , with the first 3000 time steps discarded to avoid the influence of transient state.
is the probability for a free agent to choose + with the first and second terms representing the contributions of the pinned − and free − neighbors, respectively. In the Boolean system, 2 1, 2.5, 2.7, 3.0, respectively. In each case, the value of the pinning pattern indicator η + ranges from 0.6 to 1.0. the values of attendance A oscillate about its equilibrium value 11 . The transition probability between the state at t and + t 2 can be expressed as a function of η + : (7) takes into account the effect of pinning patterns, which was ignored previously 11 . The resulting balance equation governing the dynamics of the Markov chains becomes which is the discrete-time master equation. The stable state that the system evolves into can be defined in the matrix form as and P A is the corresponding vector of ( ) P A with A ranging from 0 to N.
The probability distribution ( ) P A is a binomial function with various expectation values, as shown in Fig. 3. In addition, the probability ( ) P A is zero for  The theoretical prediction of σ 2 as a function of ρ p can thus be made through (a) identifying the function ρ ( ) P p p , (b) defining the matrix  that depends on η + and ρ ( ) P p p , and (c) calculating the stable state ( ) P A .
Effect of network topology on pinning control. The topology of the network system has an effect on the probability P p . For the particular case of scale-free networks with degree exponent γ = 3, our previous work 11 demonstrated that preferential pinning of the large-degree agents leads to ρ = P p p . Here, we consider systems with degree distribution , where k min is the minimum degree of the network. For the DPP scheme where pinning occurs in the order from large to small degree agents, the relation between the minimum degree of pinned agents (denoted by ) ′ k and the pinning fraction ρ p is For a given pinning fraction ρ ( ′) k p in which all the agents with > ′ k k are pinned, the probability P p for one neighbor of a given free agent to be a pinned agent is given by Here, Eqs. (11) and (12) are applicable to the DPP scheme on networks of any degree distribution ( ) P k without degree correlation. The underlying assumption in Eq. (12) is that the degrees of the neighboring agents are not correlated, i.e., the neighbors of the pinned agents obey the same degree distribution ( ) P k of the whole system. For a scale-free network, P p as a function of ρ p can be expressed as Scientific RepoRts | 6:20925 | DOI: 10.1038/srep20925 For the special case of γ = 3, Eq. (13) reduces to the specific relationship obtained earlier 11 : ρ ρ ( ) = P p p p . As indicated by Eqs. (7)(8)(9)(10), the specific form of matrix  with respect to ρ p can be obtained by substituting Eq. (13) into Eq. (7), leading to the distribution ( ) P A and finally the variance of the system σ 2 as a function of ρ p . Figure 4 displays the theoretical predicted σ 2 (dashed curves) for various values of the pinning fraction ρ p and of the pinning pattern indicator η + . The trend and, more importantly, the existence of the optimal pinning fraction ρ ⁎ p , agree well with the simulation results (marked with different symbols). In the limit → ∞ k , the system approaches a well-mixed state that can be fully characterized by Eq. (13), indicating that the simulation results approach the curve predicted by the mean-field theory as the average degree k is increased. Figure 5 shows the theoretical prediction of σ 2 for scale-free networks with different values of the degree exponent γ, which agrees well with the results from direct simulation as in Fig. 2. For the case of highly heterogeneous networks γ ( = . ) 2 1 , the theoretical prediction deviates slightly from the numerical results for the reason that the networks in simulation inevitably exhibit certain topological features that are not taken into account in the theoretical analysis of ρ ( ) P p p , such as the degree correlation.
Optimal pinning. Our analysis based on the master equation (8)  , from which we have At the next time step, the expected value of the state based on ρ( ) t through the response matrix  can be written asˆˆˆρ Substituting Eq. (14) into Eq. (15), we get the relationship between ρ( + ) t 1 and ρ( ) t . A self-consistency process stipulated by Eqs. (14) and (15) can yield the stable state of the system with the expected number of agents choosing + given by In a free system without pinning, the rational response  of agents to nonidentical capacities of resources leads to Eq. (3), implying the relationship = /( + ) (16), we can obtain ε as a function of the value of the pinning pattern indicator η + , the elements of the matrix , the pinning fraction ρ p , and the parameter P p associated with network topology. We have Optimal pinning pattern and fraction. Optimizing the system requires minimum which respectively correspond to the optimal value of the pinning pattern indicator η + ⁎ and the optimal pinning fraction ρ ⁎ p . Here, for convenience, we define a parameter: β ≡ ( + )/( + − ) Once the values of η + and ρ p satisfy either Eq. (18a) or Eq. (18b), we can obtain ε ( ) = X 0 2 . The variance σ 2 depends on the fluctuation factor δ ( ) X 1 only. Equation (18a) specifies the pinning pattern with the same ratio as that of the resource capacity. The Boolean dynamics studied previously 11 is a special case where the optimal pinning pattern indicator is η η / = + − ⁎ ⁎ 1 (i.e., ) η = .
+ ⁎ 0 5 for systems with = + − C C , and the variance σ 2 is simply determined by the factor δ ( ) X 1 alone. From Eq. (18b), we see that the optimal pinning fraction ρ ⁎ p is independent of η + but depends on both the network structure through ρ ( ) P p p and on the response function . Additionally, the condition ρ ∈ , [0 1] p and nonzero denominator require The function ρ ( ) P p p for scale-free networks, as in Eq. (13), increases monotonically with ρ p . Figure 6(a)   following analysis. In particular, without an analytical expression of ρ ( ) P p p , the derivative of ρ ( ) P p p with respect to ρ p can be obtained from Eqs. (11) and (12) , ensuring the existence of a nonzero ρ ⁎ p value for ε = 0. The contour map of the optimal pinning fraction ρ ⁎ p in the parameter space of + − F and − + F for scale-free networks with γ = 3 is shown in Fig. 6(b)  40. For random networks, the existence of nonzero ρ ⁎ p solutions requires that Eqs. (19) and (21) or (22) hold. For the Poisson degree distribution, the maximum degree of the network can be calculated from We can obtain an estimate of the value of β / 1 that satisfies Eq. (22), as indicated by the blue arrow (labeled as boundary 2) in Fig. 6(d). The right-hand side of this point satisfies both Eqs. (19) and (22), implying the existence of nonzero ρ ⁎ p . Comparison of the results from random and scale-free networks with different scaling exponents (Figs 2,5 and 6) shows that, stronger heterogeneity tends to enhance the values of ρ ⁎ p , which can also be seen from Eq. (20).
To better understand the non-monotonic behavior of σ 2 with ρ p , we provide a physical picture of the behavioral change for ρ p greater or less than ρ ⁎ p . The effect of pinning control is determined by the number of edges between pinned and free agents, which are pinning-free edges. For a small pinning fraction ρ p , the average effect per pinned agent on the system (represented by the number of pinned-free edges per pinned agent) is relatively large. However, as ρ p is increased, the average impact is reduced for two reasons: (a) an increase in the edges within the pinned agents' community itself (i.e., two connected pinned agents), which has no effect on control, and (b) a decrease in the number of free agents, which directly reduces the number of pinned-free edges. Consider the special case of η = + 1 and = + − C C . For small ρ p , the pinned + agents have a significant impact so that the free agents tend to overestimate the probability of winning by adopting − . In this case, the expected value ⁎ A is smaller than 0.5N, corresponding to ε < 0. For highly heterogeneous systems, the average impact per pinned agent is larger for a given small value of ρ p . As ρ p is increased, the average influence per pinned agent reduces and, consequently, ⁎ A restores towards . N 0 5 . For = .
⁎ A N 0 5 and ε = 0, the system variance [Eq. (5)] is minimized due to ε ( ) = X 0 2 , and the corresponding pinning fraction achieves the optimal value ρ ⁎ p . For strongly heterogeneous systems, due to the large initial average impact caused by pinning the hub agents, the optimal pinning fraction ρ ⁎ p appears in the larger ρ p region. Further increase in ρ p with η = + 1 will lead to ε > 0 and > . ⁎ A N 0 5 , thereby introducing nonzero ε ( ) X 2 again and, consequently, generating an increasing trend in σ 2 .

Collapse of variance.
For certain networks, the variance σ η ρ ( , ) + p 2 is determined by the values of the pinning pattern indicator η + and the pinning fraction ρ p . Our analysis so far focuses on the contribution of ε ( ) X 2 to the variance σ 2 as the pinning fraction ρ p is increased but for fixed η + . It is thus useful to define a quantity related to the variance σ 2 , which can be expressed in the form of separated variables. For two different values of the pinning pattern indicator, η + and η ′ + , for a given value of ρ p , the relative weight of ε ( ) X 2 can be obtained from Eq.  where κ ρ ( ) p is independent of the change in η + , and η Ω( ) + is independent of ρ p . The consequence of Eq. (29) is remarkable, since it defines in the parameter space η ρ ( , ) + p a function Π in the form of separated variables which, as compared with the original quantity σ 2 , not only simplifies the description but also gives a more intuitive picture of the system behavior. Specifically, for the MG dynamics, the influences of various factors on the variance σ 2 or η ρ Π( , ) + p can be classified into two parts: (I) the function κ that reflects the effects of the pinning fraction ρ p and the network structure among agents (in terms of the degree distribution ( ) P k , the average degree k , and the scaling exponent γ), and (II) the function Ω that characterizes the impact of the pinning pattern indicator η + and the response of agents to resource capacities + C and − C through . Figure 8(a,b) show the values of κ as a function of ρ p for η ′ = . where η ′ + specifies the reference pinning pattern. Once we have the two respective σ η ρ ( , ) + p 2 curves for the two specific pinning patterns as specified by η ′ + and η ″ + , σ 2 in the whole parameter space η ρ ( , ) + p can be calculated accordingly. In particular, the quantities σ η ρ ( ′, ) + p 2 and σ η ρ ( ″, ) + p 2 serve as a holographic representation of the dynamical behavior of the system in the whole parameter space. In particular, one can first obtain η Ω( ) + from Eqs (17) and (26) Analysis of Gini index. The equality of wealth is also an important criterion to assess the performance of a resource allocation system, which can be characterized by the Gini index. For MG systems without control, it was found that inequality in wealth can be pronounced when the resource utility is optimized 63 . We calculate the Gini index to uncover the interplay between pinning control and wealth equality in Boolean systems. In particular, the Gini index is defined as where N is the total number of agents in the system and g j is the ratio of the wealth earned by agent j over the total amount of wealth in the whole system. Note that g j is ranked in the ascending order as ≤ ≤ ≤  g g g N 1 2 . During each round of the game (each time step), the wealth of each minority agent is set to increase by one unit, while the wealth of the majority agents is unchanged. The accumulated wealth of each agent over a long time interval (e.g., = T 500 time steps) can be used to calculate the Gini index of the system according to its definition. Figure 9 shows the value of the Gini index G 0 as a function of ρ p , where panels (a-c) are the results for scale-free 2 1, 2.7, and 3.0, are shown in panels (d-f), respectively. In each panel, the value of the pinning pattern indicator η + ranges from 0.6 to 1.0. In reference to the variance σ 2 in Figs 1 and 2 for the same networks under identical dynamical parameter setting, we see that the value of G 0 reaches a local minimum at the optimal pinning fraction ρ ⁎ p . This implies that optimal use of resources and equality in wealth in a population can be realized simultaneously through pinning control.
As shown in each panel of Fig. 9, for larger values of η + (i.e., larger biases in pinning), the value of G 0 is generally larger and more sensitive to changes in the pinning fraction ρ p , i.e., G 0 varies more rapidly with ρ p . When the system's utilization of resource is optimized at ρ ⁎ p , we have σ δ = 2 2 (because ε = 0 2 -see Eq. (5) and discussions). We see that the Gini index can be determined through the fluctuation δ 2 of ( ) A t . As a result, if the pinning scheme is more biased (a larger value of η ) + , the fluctuations of ( ) A t are smaller, leading to a smaller value of G 0 . In addition, for the scale-free networks with larger average degree k , G 0 increases more rapidly as ρ p is increased from zero.

Discussions
The phenomenon of herding is ubiquitous in social and economical systems. Herding behavior may play a positive role in certain types of dynamical processes, with examples such as promoting cooperation in evolutionary game dynamics [64][65][66] and encouraging vaccination to prevent or suppress epidemic spreading 67 . However, in systems that involve and/or rely on fair resource allocation, the emergence of herding behavior is undesirable, as in such a state a vast majority of the individuals in the system share only a few resources, a precursor of system collapse at a global scale. A generic manifestation of herding behavior is relatively large fluctuations in the dynamical variables of the system such as the numbers of individuals sharing certain resources. It is thus desirable to develop effective control methods to suppress herding. An existing and powerful mathematical framework to model and understand the herding behavior is minority games. Investigating control of herding in the MG framework may provide useful insights into developing more realistic control method for real-world systems.
Built upon our previous works in MG systems 4,11 , in this paper we articulate, test, and analyze a general pinning scheme to control herding behavior in MG systems. A striking finding is the universal existence of an optimal pinning fraction that minimizes the variance and realizes the equality among the agents in the system, regardless of system details such as the degree of homogeneity of the resource capacities, topology and structures of the underlying network, and different patterns of pinning. This means that, generally, the efficiency of the system can be optimized for some relatively small pinning fraction. Employing the mean-field approach, we develop a detailed theory to understand and predict the dynamics of the MG system subject to pinning control, for various network topologies and pinning schemes. The key observation underlying our theory is the two factors contributing to the system fluctuations: intrinsic dynamical fluctuations and systematic deviation of agents' expected attendance from resource capacity. The theoretically predicted fluctuations (quantified by the system variance) agree with those from direct simulation. In particular, in the large degree limit, for a variety of combinations of the network and pinning parameters, the numerical results approach those predicted from our mean field theory. Our theory also correctly predicts the optimal pinning fraction for various system and control settings. In real world systems in which resource allocation is an important component, resource capacities and agent interactions can be diverse and time dependent. To develop MG model to understand the effects of diversity and time dependence on herding dynamics, and to exploit the understanding to develop pinning control methods to suppress or eliminate herding are open issues at the present. Furthermore, implementation of pinning control in real systems may be associated with incentive policies that provide compensations or rewards to the pinned agents. How to reduce the optimal pinning fraction then becomes an interesting issue. Our results provide insights and represent a step toward the goal of designing highly stable and efficient resource allocation systems.