Returns the solution of the BV algorithm

        :return: a tuple of string corresponding to the dot-product partner vector and the bias term
        :rtype: Tuple[String, String]
357179
def get_solution(self) -> Tuple[str, str]:
        
        if self.solution is None:
            raise AssertionError("You need to `run` this algorithm first")
        return self.solution
1109185
def solve(self):
        
        if not isinstance(self.cube, Cube):
            raise ValueError("Use Solver.feed(cube) to feed the cube to solver.")
        self.recognise()
        self.cube(algo_dict[self.case])
        return algo_dict[self.case]
309502
def seriesflow(self, dae):
        

        # Vm = dae.y[self.v]
        # Va = dae.y[self.a]
        # V1 = polar(Vm[self.a1], Va[self.a1])
        # V2 = polar(Vm[self.a2], Va[self.a2])

        I1 = mul(self.v1, div(self.y12 + self.y1, self.m2)) - \
            mul(self.v2, div(self.y12, self.mconj))
        I2 = mul(self.v2, self.y12 + self.y2) - \
            mul(self.v2, div(self.y12, self.m))

        self.I1_real = I1.real()
        self.I1_imag = I1.imag()
        self.I2_real = I2.real()
        self.I2_imag = I2.imag()

        self.S1 = mul(self.v1, conj(I1))
        self.S2 = mul(self.v2, conj(I2))

        self.P1 = self.S1.real()
        self.P2 = self.S2.real()
        self.Q1 = self.S1.imag()
        self.Q2 = self.S2.imag()

        self.chg1 = mul(self.g1 + 1j * self.b1, div(self.v1**2, self.m2))
        self.chg2 = mul(self.g2 + 1j * self.b2, self.v2**2)

        self.Pchg1 = self.chg1.real()
        self.Pchg2 = self.chg2.real()

        self.Qchg1 = self.chg1.imag()
        self.Qchg2 = self.chg2.imag()

        self._line_flows = matrix([self.P1, self.P2, self.Q1, self.Q2,
                                   self.I1_real, self.I1_imag,
                                   self.I2_real, self.I2_imag])
659829
def vector_dot(vector1, vector2):
    
    try:
        if vector1 is None or len(vector1) == 0 or vector2 is None or len(vector2) == 0:
            raise ValueError("Input vectors cannot be empty")
    except TypeError as e:
        print("An error occurred: {}".format(e.args[-1]))
        raise TypeError("Input must be a list or tuple")
    except Exception:
        raise

    # Compute dot product
    prod = 0.0
    for v1, v2 in zip(vector1, vector2):
        prod += v1 * v2

    # Return the dot product of the input vectors
    return prod
807931
private static Vector2d getPerpendicular(Tuple2d a, Tuple2d b, Vector2d ref) {
        final Vector2d pVec = new Vector2d(-(a.y-b.y), a.x-b.x);
        if (pVec.dot(ref) < 0)
            pVec.negate();
        return pVec;
    }
565991
def solve(self, lam):
        ''''''
        s = weighted_graphtf(self.nnodes, self.y, self.weights, lam,
                             self.Dk.shape[0], self.Dk.shape[1], self.Dk.nnz,
                             self.Dk.row.astype('int32'), self.Dk.col.astype('int32'), self.Dk.data.astype('double'),
                             self.maxsteps, self.converge,
                             self.beta, self.u)
        self.steps.append(s)
        return self.beta
241475
def d2Ibr_dV2(Ybr, V, lam):
    
    nb = len(V)
    diaginvVm = spdiag(div(matrix(1.0, (nb, 1)), abs(V)))

    Haa = spdiag(mul(-(Ybr.T * lam), V))
    Hva = -1j * Haa * diaginvVm
    Hav = Hva
    Hvv = spmatrix([], [], [], (nb, nb))

    return Haa, Hav, Hva, Hvv
1266432
def solve_with_cvxopt(sdp, solverparameters=None):
    
    P = convert_to_picos(sdp)
    P.set_option("solver", "cvxopt")
    P.set_option("verbose", sdp.verbose)
    if solverparameters is not None:
        for key, value in solverparameters.items():
            P.set_option(key, value)
    solution = P.solve()
    x_mat = [np.array(P.get_valued_variable('X'))]
    y_mat = [np.array(P.get_constraint(i).dual)
             for i in range(len(P.constraints))]
    return -solution["cvxopt_sol"]["primal objective"] + \
        sdp.constant_term, \
        -solution["cvxopt_sol"]["dual objective"] + \
        sdp.constant_term, \
        x_mat, y_mat, solution["status"]
507002
def volume( self ):
        
        return np.dot( self.matrix[0], np.cross( self.matrix[1], self.matrix[2] ) )
1199464
def dot_solve(self, y):
        

        """
        return np.dot(y.T, cho_solve(self._factor, y))
445961
def _update_solution_data(self, s):
        
        x = s["x"]
#        Va_var = self.om.get_var("Va")
#        Vm_var = self.om.get_var("Vm")
#        Pg_var = self.om.get_var("Pg")
#        Qg_var = self.om.get_var("Qg")

        Va = x[self._Va.i1:self._Va.iN + 1]
        Vm = x[self._Vm.i1:self._Vm.iN + 1]
        Pg = x[self._Pg.i1:self._Pg.iN + 1]
        Qg = x[self._Qg.i1:self._Qg.iN + 1]

#        f = 0.5 * dot(x.T * HH, x) + dot(CC.T, x)

#        s["f"] = s["f"] + C0

        # Put the objective function value in the solution.
#        solution["f"] = f

        return Va, Vm, Pg, Qg
1001925
def get_explicit_residual(self, indices=None):
        ''''''
        ritz_vecs = self.get_vectors(indices)
        return self._deflated_solver.linear_system.MlAMr * ritz_vecs \
            - ritz_vecs * self.values
493866
def dot_v3(v, w):
    """"""

    return sum([x * y for x, y in zip(v, w)])
438963
def solve_with_cvxpy(sdp, solverparameters=None):
    
    problem = convert_to_cvxpy(sdp)
    if solverparameters is not None and 'solver' in solverparameters:
        solver = solverparameters.pop('solver')
        v = problem.solve(solver=solver, verbose=(sdp.verbose > 0))
    else:
        v = problem.solve(verbose=(sdp.verbose > 0))
    if v is None:
        status = "infeasible"
        x_mat, y_mat = [], []
    elif v == float("inf") or v == -float("inf"):
        status = "unbounded"
        x_mat, y_mat = [], []
    else:
        status = "optimal"
        x_pre = sdp.F[:, 1:sdp.n_vars+1].dot(problem.variables()[0].value)
        x_pre += sdp.F[:, 0]
        row_offsets = [0]
        cumulative_sum = 0
        for block_size in sdp.block_struct:
            cumulative_sum += block_size ** 2
            row_offsets.append(cumulative_sum)
        x_mat = []
        for bi, bs in enumerate(sdp.block_struct):
            x = x_pre[row_offsets[bi]:row_offsets[bi+1]].reshape((bs, bs))
            x += x.T - np.diag(np.array(x.diagonal())[0])
            x_mat.append(x)
        y_mat = [constraint.dual_value for constraint in problem.constraints]
    return v+sdp.constant_term, v+sdp.constant_term, x_mat, y_mat, status
261430
def solution_blobs(self, tx, tx_in_idx):
        
        sc = tx.SolutionChecker(tx)
        tx_context = sc.tx_context_for_idx(tx_in_idx)
        # set solution_stack in case there are no results from puzzle_and_solution_iterator
        solution_stack = []
        for puzzle_script, solution_stack, flags, sighash_f in sc.puzzle_and_solution_iterator(tx_context):
            pass
            # we only care about the last one
        for s in solution_stack:
            yield s
1269327
def solution_path(self):
        ''''''
        lambda_grid = np.exp(np.linspace(np.log(self.max_lambda), np.log(self.min_lambda), self.lambda_bins))
        aic_trace = np.zeros((len(self.bins),lambda_grid.shape[0])) # The AIC score for each lambda value
        aicc_trace = np.zeros((len(self.bins),lambda_grid.shape[0])) # The AICc score for each lambda value (correcting for finite sample size)
        bic_trace = np.zeros((len(self.bins),lambda_grid.shape[0])) # The BIC score for each lambda value
        dof_trace = np.zeros((len(self.bins),lambda_grid.shape[0])) # The degrees of freedom of each final solution
        log_likelihood_trace = np.zeros((len(self.bins),lambda_grid.shape[0]))
        bic_best_idx = [None for _ in self.bins]
        aic_best_idx = [None for _ in self.bins]
        aicc_best_idx = [None for _ in self.bins]
        bic_best_betas = [None for _ in self.bins]
        aic_best_betas = [None for _ in self.bins]
        aicc_best_betas = [None for _ in self.bins]
        if self.k == 0 and self.trails is not None:
            betas = [np.zeros(self.num_nodes, dtype='double') for _ in self.bins]
            zs = [np.zeros(self.breakpoints[-1], dtype='double') for _ in self.bins]
            us = [np.zeros(self.breakpoints[-1], dtype='double') for _ in self.bins]
        else:
            betas = [np.zeros(self.num_nodes, dtype='double') for _ in self.bins]
            us = [np.zeros(self.Dk.shape[0], dtype='double') for _ in self.bins]
        for i, _lambda in enumerate(lambda_grid):
            if self.verbose:
                print('\n#{0} Lambda = {1}'.format(i, _lambda))

            # Run the graph fused lasso over each bin with the current lambda value
            initial_values = (betas, zs, us) if self.k == 0 and self.trails is not None else (betas, us)
            self.run(_lambda, initial_values=initial_values)

            if self.verbose > 1:
                print('\tCalculating degrees of freedom and information criteria')

            for b, beta in enumerate(betas):
                if self.bins_allowed is not None and b not in self.bins_allowed:
                    continue

                # Count the number of free parameters in the grid (dof)
                # TODO: this is not really the true DoF, since a change in a higher node multiplies
                # the DoF in the lower nodes
                # dof_trace[b,i] = len(self.calc_plateaus(beta))
                dof_vals = self.Dk_minus_one.dot(beta) if self.k > 0 else beta
                plateaus = calc_plateaus(dof_vals, self.edges, rel_tol=0.01) if (self.k % 2) == 0 else nearly_unique(dof_vals, rel_tol=0.03)
                #plateaus = calc_plateaus(dof_vals, self.edges, rel_tol=1e-5) if (self.k % 2) == 0 else nearly_unique(dof_vals, rel_tol=1e-5)
                dof_trace[b,i] = max(1,len(plateaus)) #* (k+1)

                # Get the negative log-likelihood
                log_likelihood_trace[b,i] = self.data_log_likelihood(self.bins[b][-1], self.bins[b][-2], beta)

                # Calculate AIC = 2k - 2ln(L)
                aic_trace[b,i] = 2. * dof_trace[b,i] - 2. * log_likelihood_trace[b,i]
                
                # Calculate AICc = AIC + 2k * (k+1) / (n - k - 1)
                aicc_trace[b,i] = aic_trace[b,i] + 2 * dof_trace[b,i] * (dof_trace[b,i]+1) / (self.num_nodes - dof_trace[b,i] - 1.)

                # Calculate BIC = -2ln(L) + k * (ln(n) - ln(2pi))
                bic_trace[b,i] = -2 * log_likelihood_trace[b,i] + dof_trace[b,i] * (np.log(self.num_nodes) - np.log(2 * np.pi))

                # Track the best model thus far
                if aic_best_idx[b] is None or aic_trace[b,i] < aic_trace[b,aic_best_idx[b]]:
                    aic_best_idx[b] = i
                    aic_best_betas[b] = np.array(beta)

                # Track the best model thus far
                if aicc_best_idx[b] is None or aicc_trace[b,i] < aicc_trace[b,aicc_best_idx[b]]:
                    aicc_best_idx[b] = i
                    aicc_best_betas[b] = np.array(beta)

                # Track the best model thus far
                if bic_best_idx[b] is None or bic_trace[b,i] < bic_trace[b,bic_best_idx[b]]:
                    bic_best_idx[b] = i
                    bic_best_betas[b] = np.array(beta)

                if self.verbose and self.bins_allowed is not None:
                    print('\tBin {0} Log-Likelihood: {1} DoF: {2} AIC: {3} AICc: {4} BIC: {5}'.format(b, log_likelihood_trace[b,i], dof_trace[b,i], aic_trace[b,i], aicc_trace[b,i], bic_trace[b,i]))

            if self.verbose and self.bins_allowed is None:
                print('Overall Log-Likelihood: {0} DoF: {1} AIC: {2} AICc: {3} BIC: {4}'.format(log_likelihood_trace[:,i].sum(), dof_trace[:,i].sum(), aic_trace[:,i].sum(), aicc_trace[:,i].sum(), bic_trace[:,i].sum()))

        if self.verbose:
            print('')
            print('Best settings per bin:')
            for b, (aic_idx, aicc_idx, bic_idx) in enumerate(zip(aic_best_idx, aicc_best_idx, bic_best_idx)):
                if self.bins_allowed is not None and b not in self.bins_allowed:
                    continue
                left, mid, right, trials, successes = self.bins[b]
                print('\tBin #{0} ([{1}, {2}], split={3}) lambda: AIC={4:.2f} AICC={5:.2f} BIC={6:.2f} DoF: AIC={7:.0f} AICC={8:.0f} BIC={9:.0f}'.format(
                        b, left, right, mid,
                        lambda_grid[aic_idx], lambda_grid[aicc_idx], lambda_grid[bic_idx],
                        dof_trace[b,aic_idx], dof_trace[b,aicc_idx], dof_trace[b,bic_idx]))
            print('')

        if self.bins_allowed is None:
            if self.verbose:
                print('Creating densities from betas...')
            bic_density = self.density_from_betas(bic_best_betas)
            aic_density = self.density_from_betas(aic_best_betas)
            aicc_density = self.density_from_betas(aicc_best_betas)
            self.map_density = bic_density
        else:
            aic_density, aicc_density, bic_density = None, None, None
        
        self.map_betas = bic_best_betas

        return {'aic': aic_trace,
                'aicc': aicc_trace,
                'bic': bic_trace,
                'dof': dof_trace,
                'loglikelihood': log_likelihood_trace,
                'lambdas': lambda_grid,
                'aic_betas': aic_best_betas,
                'aicc_betas': aicc_best_betas,
                'bic_betas': bic_best_betas,
                'aic_best_idx': aic_best_idx,
                'aicc_best_idx': aicc_best_idx,
                'bic_best_idx': bic_best_idx,
                'aic_densities': aic_density.reshape(self.data_shape),
                'aicc_densities': aicc_density.reshape(self.data_shape),
                'bic_densities': bic_density.reshape(self.data_shape)}
461083
def get_ptrms_angle(ptrms_best_fit_vector, B_lab_vector):
    
    ptrms_angle = math.degrees(math.acos(old_div(numpy.dot(ptrms_best_fit_vector,B_lab_vector),(numpy.sqrt(sum(ptrms_best_fit_vector**2)) * numpy.sqrt(sum(B_lab_vector**2))))))  # from old thellier_gui.py code  
    return ptrms_angle