Computes the "cost" for the parameters given.

cost = (1/N) Sum (f(x) - y)^2
331759
private double cost(DMatrixRMaj param )
    {
        function.compute(param, residuals);

        double error = NormOps_DDRM.normF(residuals);

        return error*error / (double)residuals.numRows;
    }
9314
def f(self, y):
        
        d = self.d
        mpsi = self.psi
        z = d * y.copy()
        for i in range(len(mpsi)):
            a, b, c = mpsi[i]
            z += a * np.tanh(b * (y + c))
        return z
584237
def edge_cost(self, node_a, node_b):
        """"""
        cost = float('inf')
        node_object_a = self.get_node(node_a)
        for edge_id in node_object_a['edges']:
            edge = self.get_edge(edge_id)
            tpl = (node_a, node_b)
            if edge['vertices'] == tpl:
                cost = edge['cost']
                break
        return cost
809789
def cost_min2(self, alpha):
        
        n = self.V.dim()
        ax = alpha[:n]
        ay = alpha[n:]

        # ml = pyamg.ruge_stuben_solver(self.L)
        # # ml = pyamg.smoothed_aggregation_solver(self.L)
        # print(ml)
        # print()
        # print(self.L)
        # print()
        # x = ml.solve(ax, tol=1e-10)
        # print('residual: {}'.format(numpy.linalg.norm(ax - self.L*x)))
        # print()
        # print(ax)
        # print()
        # print(x)
        # exit(1)

        # x = sparse.linalg.spsolve(self.L, ax)
        # print('residual: {}'.format(numpy.linalg.norm(ax - self.L*x)))
        # exit(1)

        q2, r2 = self.get_q2_r2(ax, ay)

        Lax = self.L * ax
        Lay = self.L * ay

        out = [
            0.5 * numpy.dot(Lax, Lax),
            0.5 * numpy.dot(Lay, Lay),
            0.5 * numpy.dot(q2 - 1, q2 - 1),
            0.5 * numpy.dot(r2, r2),
        ]

        if self.num_f_eval % 10000 == 0:
            print("{:7d}     {:e} {:e} {:e} {:e}".format(self.num_f_eval, *out))

        self.num_f_eval += 1
        return numpy.sum(out)
402751
private static double computeCost(
      int[] assignments,
      double[][] costMatrix,
      double[] sourceTermDeletionCosts,
      double[] targetTermDeletionCosts) {

    // We need to sum the costs of each assigned pair, each unassigned source term, and each
    // unassigned target term.

    // Start with the total cost of _not_ using all the target terms, then when we use one we'll
    // remove it from this total.
    double totalCost = DoubleStream.of(targetTermDeletionCosts).sum();
    for (int sourceTermIndex = 0; sourceTermIndex < assignments.length; sourceTermIndex++) {
      int targetTermIndex = assignments[sourceTermIndex];
      if (targetTermIndex == -1) {
        // not using this source term
        totalCost += sourceTermDeletionCosts[sourceTermIndex];
      } else {
        // add the cost of the assignments
        totalCost += costMatrix[sourceTermIndex][targetTermIndex];

        // we are using this target term and so we should remove the cost of deleting it
        totalCost -= targetTermDeletionCosts[targetTermIndex];
      }
    }
    return totalCost;
  }
1145657
def compute_total(self, precision=None):
        '''
        
        '''
        return quantize(sum([line.compute_total(precision) for line
                             in self.__lines]), places=precision) or ZERO
200451
public double computeAverage (Function<Triple<GeneralDataset<L, F>,GeneralDataset<L, F>,SavedState>,Double> function) 
  {
    double sum = 0;
    Iterator<Triple<GeneralDataset<L, F>,GeneralDataset<L, F>,SavedState>> foldIt = iterator();
    while (foldIt.hasNext()) {
      sum += function.apply(foldIt.next());
    }
    return sum / kfold;
  }
915461
def acquisition_function_withGradients(self, x):
        
        f_acqu,df_acqu = self._compute_acq_withGradients(x)
        cost_x, cost_grad_x = self.cost_withGradients(x)
        f_acq_cost = f_acqu/cost_x
        df_acq_cost = (df_acqu*cost_x - f_acqu*cost_grad_x)/(cost_x**2)
        return -f_acq_cost*self.space.indicator_constraints(x), -df_acq_cost*self.space.indicator_constraints(x)
910583
def _quadratic_costs(self, generators, ipol, nxyz, base_mva):
        
        npol = len(ipol)
        rnpol = range(npol)
        gpol = [g for g in generators if g.pcost_model == POLYNOMIAL]

        if [g for g in gpol if len(g.p_cost) > 3]:
            logger.error("Order of polynomial cost greater than quadratic.")

        iqdr = [i for i, g in enumerate(generators)
                if g.pcost_model == POLYNOMIAL and len(g.p_cost) == 3]
        ilin = [i for i, g in enumerate(generators)
                if g.pcost_model == POLYNOMIAL and len(g.p_cost) == 2]

        polycf = zeros((npol, 3))
        if npol > 0:
            if len(iqdr) > 0:
                polycf[iqdr, :] = array([list(g.p_cost)
                                         for g in generators])#[iqdr, :].T
            if len(ilin) > 0:
                polycf[ilin, 1:] = array([list(g.p_cost[:2])
                                          for g in generators])#[ilin, :].T
            # Convert to per-unit.
            polycf = polycf * array([base_mva**2, base_mva, 1])
            Pg = self.om.get_var("Pg")
            Npol = csr_matrix((ones(npol), (rnpol, Pg.i1 + array(ipol))),
                              (npol, nxyz))
            Hpol = csr_matrix((2 * polycf[:, 0], (rnpol, rnpol)), (npol, npol))
            Cpol = polycf[:, 1]
            fparm_pol = (ones(npol) * array([[1], [0], [0], [1]])).T
        else:
            Npol = Hpol = None
            Cpol = array([])
            fparm_pol = zeros((0, 4))

        return Npol, Hpol, Cpol, fparm_pol, polycf, npol
895183
def compute(self, x):
        '''
        
        '''
        q_learning = copy(self.__greedy_q_learning)
        q_learning.epsilon_greedy_rate = x[0]
        q_learning.alpha_value = x[1]
        q_learning.gamma_value = x[2]
        if self.__init_state_key is not None:
            q_learning.learn(state_key=self.__init_state_key, limit=int(x[3]))
        else:
            q_learning.learn(limit=x[3])
        q_sum = q_learning.q_df.q_value.sum()
        if q_sum != 0:
            cost = q_learning.q_df.shape[0] / q_sum
        else:
            cost = q_learning.q_df.shape[0] / 1e-4

        return cost
159140
def calc_cost(self, node_a, node_b):
        
        if node_b.x - node_a.x == 0 or node_b.y - node_a.y == 0:
            # direct neighbor - distance is 1
            ng = 1
        else:
            # not a direct neighbor - diagonal movement
            ng = SQRT2

        # weight for weighted algorithms
        if self.weighted:
            ng *= node_b.weight

        return node_a.g + ng
805836
def compute(self, x, y):
        '''
        
        '''
        if x in self.__memo_dict:
            x_v = self.__memo_dict[x]
        else:
            x_v = self.__cost_functionable.compute(self.__params_arr[x, :])
            self.__memo_dict.setdefault(x, x_v)
        if y in self.__memo_dict:
            y_v = self.__memo_dict[y]
        else:
            y_v = self.__cost_functionable.compute(self.__params_arr[y, :])
            self.__memo_dict.setdefault(y, y_v)

        return abs(x_v - y_v)
503612
def _cost_method(self, *args, **kwargs):
        

        cost_val = 0.5 * np.linalg.norm(self.obs_data - self.op(args[0])) ** 2

        if 'verbose' in kwargs and kwargs['verbose']:
            print(' - DATA FIDELITY (X):', cost_val)

        return cost_val
1328709
function sum() {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        var sum = 0;
        if (args.length > 0) {
            args.map(function (number) {
                if (isNumber(number)) {
                    sum += number;
                }
            });
        }
        return sum;
    }
785076
def acquisition_function(self,x):
        
        f_acqu = self._compute_acq(x)
        cost_x, _ = self.cost_withGradients(x)
        return -(f_acqu*self.space.indicator_constraints(x))/cost_x
1155113
public double Function2D(double x, double y) {
        double frequency = initFrequency;
        double amplitude = initAmplitude;
        double sum = 0;

        // octaves
        for (int i = 0; i < octaves; i++) {
            sum += SmoothedNoise(x * frequency, y * frequency) * amplitude;

            frequency *= 2;
            amplitude *= persistence;
        }
        return sum;
    }
778329
def total_cost(self, p=None, p_cost=None, pcost_model=None):
        
        p = self.p if p is None else p
        p_cost = self.p_cost if p_cost is None else p_cost
        pcost_model = self.pcost_model if pcost_model is None else pcost_model

        p = 0.0 if not self.online else p

        if pcost_model == PW_LINEAR:
            n_segments = len(p_cost) - 1
            # Iterate over the piece-wise linear segments.
            for i in range(n_segments):
                x1, y1 = p_cost[i]
                x2, y2 = p_cost[i + 1]
                m = (y2 - y1) / (x2 - x1)
                c = y1 - m * x1
                if x1 <= p <= x2:
                    result = m*p + c
                    break
            else:
#                print "TOTC:", self.name, p, self.p_max, p_cost

#                raise ValueError, "Value [%f] outwith pwl cost curve." % p

                # Use the last segment for values outwith the cost curve.
                logger.error("Value [%f] outside pwl cost curve [%s]." %
                             (p, p_cost[-1][0]))
                result = m*p + c
        elif pcost_model == POLYNOMIAL:
#            result = p_cost[-1]
#            for i in range(1, len(p_cost)):
#                result += p_cost[-(i + 1)] * p**i
            result = polyval(p_cost, p)
        else:
            raise ValueError

        if self.is_load:
            return -result
        else:
            return result