Return a randomly weighted sum of the force vectors.

    args:
        force_vectors: A list of force vectors on solution i.

    returns:
        numpy.array; The total force on solution i.
4619
def _gsa_total_force(force_vectors, vector_length):
    
    if len(force_vectors) == 0:
        return [0.0] * vector_length
    # The GSA algorithm specifies that the total force in each dimension
    # is a random sum of the individual forces in that dimension.
    # For this reason we sum the dimensions individually instead of simply
    # using vec_a+vec_b
    total_force = [0.0] * vector_length
    for force_vec in force_vectors:
        for i in range(vector_length):
            total_force[i] += random.uniform(0.0, 1.0) * force_vec[i]
    return total_force
1052335
def addPointVectors(self, vectors, name):
        
        poly = self.polydata(False)
        if len(vectors) != poly.GetNumberOfPoints():
            colors.printc('~times addPointVectors Error: Number of vectors != nr. of points',
                          len(vectors), poly.GetNumberOfPoints(), c=1)
            exit()
        arr = vtk.vtkDoubleArray()
        arr.SetNumberOfComponents(3)
        arr.SetName(name)
        for v in vectors:
            arr.InsertNextTuple(v)
        poly.GetPointData().AddArray(arr)
        poly.GetPointData().SetActiveVectors(name)
        return self
1352850
def _phiforce(self,R,phi=0.,t=0.):
        
        return self._Pot.phiforce(R,0.,phi=phi,t=t,use_physical=False)
1164346
def sum(self, vector):
        """"""
        return self.from_list(
            [x + vector.vector[i] for i, x in self.to_list()]
        )
868646
def force(self,c):
        ''''''
        
        # bring instance variables into local scope
        x = self.x
        v = self.v
        b = self.b
        k = self.k
        x0 = self.x0
        
        F = self.control_force(c)
        
        return F - b*v - k*(x - x0)
284464
def get_potential_energy(self, a=None):
        """"""
        if a is None:
            a = self.a
        if self.mask is None:
            return -np.sum(np.dot(a.get_positions()[self.mask], self.force))
        else:
            return -np.sum(np.dot(a.get_positions(), self.force))
78870
def vectors_between_pts(pts=[]):
    '''
    '''
    assert isinstance(pts, list) and len(pts) > 0
    l_pts = len(pts)
    l_pt_prev = None
    for pt in pts:
        assert isinstance(pt, tuple)
        l_pt = len(pt)
        assert l_pt > 1
        for i in pt:
            assert isinstance(i, float)
        if l_pt_prev is not None:
            assert l_pt == l_pt_prev
        l_pt_prev = l_pt

    return [tuple([pts[(i+1) % l_pts][j] - pts[i][j] for j in range(l_pt)]) \
            for i in range(l_pts)]
513497
def calculate2d(self, force=True):
        
        for ml in (self.__reagents, self.__reactants, self.__products):
            for m in ml:
                m.calculate2d(force)
        self.fix_positions()
795243
def probabilities(self) -> bk.BKTensor:
        
        value = bk.absolute(self.tensor)
        return value * value
256665
def sum(self, weights=None):
        
        if weights is None:
            weights = self.data.weights
        return utils.bincount(self.labels, weights, self.N)
70897
def update(self, values, force=False):
        
        results = {}
        for k, v in six.iteritems(values):
            results[k] = self.__setitem__(k, v, force=force)
        return results
585978
def _get_forces(self, vasprun_etree):
        
        forces = []
        for event, element in vasprun_etree:
            if element.attrib['name'] == 'forces':
                for v in element:
                    forces.append([float(x) for x in v.text.split()])
        return np.array(forces)
771995
def weighted_n(self):
        """"""
        if not self.is_weighted:
            return float(self.unweighted_n)
        return float(sum(self._cube_dict["result"]["measures"]["count"]["data"]))
91077
def p_const_vector_vector_list(p):
    
    if len(p[3]) != len(p[1][0]):
        syntax_error(p.lineno(2), 'All rows must have the same number of elements')
        p[0] = None
        return

    p[0] = p[1] + [p[3]]
735538
def to_vector(np_array):
    
    if len(np_array.shape) == 1:
        return Vectors.dense(np_array)
    else:
        raise Exception("An MLLib Vector can only be created from a one-dimensional " +
                        "numpy array, got {}".format(len(np_array.shape)))
29523
def returnMatches(kw, kv, n, theta, inputScaling=1.0):
  
  # How many weight vectors and input vectors to generate at a time
  m1 = 4
  m2 = 1000

  weights = getSparseTensor(kw, n, m1, fixedRange=1.0 / kw)

  # Initialize random input vectors using given scaling and see how many match
  inputVectors = getSparseTensor(kv, n, m2,
                                 onlyPositive=True,
                                 fixedRange= 2*inputScaling / kw,
                                 )
  dot = inputVectors.matmul(weights.t())
  numMatches = ((dot >= theta).sum()).item()
  pctMatches = numMatches / float(m1*m2)

  return pctMatches, numMatches, m1*m2
245466
def _get_phi_vector(self, phi_mean, phi_std, imt_list):
        
        p_bar = {}
        p_std = {}

        for imt in imt_list:
            p_bar[imt] = []
            p_std[imt] = []
            for mag in self.magnitude_limits:
                phi_ss_mean = get_phi_ss(imt, mag, phi_mean)
                phi_ss_std = get_phi_ss(imt, mag, phi_std)
                if self.ergodic:
                    # Add on the phi_s2ss term according to Eqs. 5.15 and 5.16
                    # of Al Atik (2015)
                    phi_ss_mean = np.sqrt(
                        phi_ss_mean ** 2. +
                        PHI_S2SS_MODEL[self.phi_s2ss_model][imt]["mean"] ** 2.
                        )
                    phi_ss_std = np.sqrt(
                        phi_ss_std ** 2. +
                        PHI_S2SS_MODEL[self.phi_s2ss_model][imt]["var"] ** 2.
                        )
                p_bar[imt].append(phi_ss_mean)
                p_std[imt].append(phi_ss_std)
        return p_bar, p_std