Calculates the instance accommodation matrix which stores how many times a particular instance type can be
accommodated inside another instance type based on the list of available instance types.

@return the instance accommodation matrix
161386
private int[][] calculateInstanceAccommodationMatrix() {

		if (this.availableInstanceTypes == null) {
			LOG.error("Cannot compute instance accommodation matrix: availableInstanceTypes is null");
			return null;
		}

		final int matrixSize = this.availableInstanceTypes.length;
		final int[][] am = new int[matrixSize][matrixSize];

		// Populate matrix
		for (int i = 0; i < matrixSize; i++) {
			for (int j = 0; j < matrixSize; j++) {

				if (i == j) {
					am[i][j] = 1;
				} else {

					final InstanceType sourceType = this.availableInstanceTypes[i];
					InstanceType targetType = this.availableInstanceTypes[j];

					// How many times can we accommodate source type into target type?
					final int cores = targetType.getNumberOfCores() / sourceType.getNumberOfCores();
					final int cu = targetType.getNumberOfComputeUnits() / sourceType.getNumberOfComputeUnits();
					final int mem = targetType.getMemorySize() / sourceType.getMemorySize();
					final int disk = targetType.getDiskCapacity() / sourceType.getDiskCapacity();

					am[i][j] = Math.min(cores, Math.min(cu, Math.min(mem, disk)));
				}
			}
		}

		return am;
	}
411255
public Matrix getD()
    {
        Matrix X = new DenseMatrix(n, n);
        for (int i = 0; i < n; i++)
        {
            X.set(i, i, d[i]);
            
            if (e[i] > 0)
                X.set(i, i+1, e[i]);
            else if (e[i] < 0)
                X.set(i, i-1, e[i]);
        }
        return X;
    }
454000
public long computeTotalCombinations() {

		long numerator = a.size();
		long denominator = k;

		for( int i = 1; i < k; i++ ) {
			numerator *= a.size()-i;
			denominator *= k-i;
		}

		return numerator/denominator;
	}
564330
public final int getNumberOfPossibleAssignments() {
    int[] sizes = getVariableSizes();
    int numAssignments = 1;
    for (int i = 0; i < sizes.length; i++) {
      numAssignments *= sizes[i];
    }
    return numAssignments;
  }
603134
public weka.core.Instances wekaInstances(Instances instances) {
        weka.core.Instances wekaInstances = wekaInstancesInformation(instances);
        //We assume that we have only one WekaInstanceInformation for SamoaToWekaInstanceConverter
        this.wekaInstanceInformation = wekaInstances;
        for (int i = 0; i < instances.numInstances(); i++) {
            wekaInstances.add(wekaInstance(instances.instance(i)));
        }
        return wekaInstances;
    }
712950
private List<Integer> getPermutation(Matrix4d transformation) {
		double rmsdThresholdSq = Math
				.pow(this.parameters.getRmsdThreshold(), 2);

		List<Point3d> centers = subunits.getOriginalCenters();
		List<Integer> seqClusterId = subunits.getClusterIds();

		List<Integer> permutations = new ArrayList<Integer>(centers.size());
		double[] dSqs = new double[centers.size()];
		boolean[] used = new boolean[centers.size()];
		Arrays.fill(used, false);

		for (int i = 0; i < centers.size(); i++) {
			Point3d tCenter = new Point3d(centers.get(i));
			transformation.transform(tCenter);
			int permutation = -1;
			double minDistSq = Double.MAX_VALUE;
			for (int j = 0; j < centers.size(); j++) {
				if (seqClusterId.get(i) == seqClusterId.get(j)) {
					if (!used[j]) {
						double dSq = tCenter.distanceSquared(centers.get(j));
						if (dSq < minDistSq && dSq <= rmsdThresholdSq) {
							minDistSq = dSq;
							permutation = j;
							dSqs[j] = dSq;
						}
					}
				}
			}
			// can't map to itself
			if (permutations.size() == permutation) {
				permutation = -1;
			}

			if (permutation != -1) {
				used[permutation] = true;
			}

			permutations.add(permutation);
		}

		return permutations;
	}
748332
protected double[] kNNDistances() {
    int k = getEntry(0).getKnnDistances().length;

    double[] result = new double[k];

    for(int i = 0; i < getNumEntries(); i++) {
      for(int j = 0; j < k; j++) {
        MkTabEntry entry = getEntry(i);
        result[j] = Math.max(result[j], entry.getKnnDistance(j + 1));
      }
    }

    return result;
  }
154083
public java.util.List<InstanceCapacity> getAvailableInstanceCapacity() {
        if (availableInstanceCapacity == null) {
            availableInstanceCapacity = new com.amazonaws.internal.SdkInternalList<InstanceCapacity>();
        }
        return availableInstanceCapacity;
    }
1350799
public Matrix getS () {
		Matrix X = new Matrix(n,n);
		double[][] S = X.getArray();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				S[i][j] = 0.0;
			}
			S[i][i] = this.s[i];
		}
		return X;
	}
369497
public ArrayList<Integer> getOccurrences() {
    ArrayList<Integer> res = new ArrayList<Integer>(this.occurrences.size());
    for (Integer e : this.occurrences) {
      res.add(e);
    }
    return res;
  }
673598
@Override
  public int[] calculateInDegrees() {
    final int[] in_degrees = new int[size()];
    for(int i = 0; i < size(); ++i) {
      final IAdjacencyListPair<TVertex> p = pairAt(i);
      final TVertex d = p.getVertex();

      for(int j = 0; j < size(); ++j) {
        for(IVertex dep : pairAt(j).getOutNeighbors()) {
          if (d.equals(dep))
            ++in_degrees[i];
        }
      }
    }
    return in_degrees;
  }
1247069
public BinaryClassificationFMeasure evaluate(Instance[] instanceList)
    {
        int TP = 0, FP = 0, FN = 0;
        for (Instance instance : instanceList)
        {
            int y = model.decode(instance.x);
            if (y == 1)
            {
                if (instance.y == 1)
                    ++TP;
                else
                    ++FP;
            }
            else if (instance.y == 1)
                ++FN;
        }
        float p = TP / (float) (TP + FP) * 100;
        float r = TP / (float) (TP + FN) * 100;
        return new BinaryClassificationFMeasure(p, r, 2 * p * r / (p + r));
    }
337781
public Matrix times(Matrix B)
    {
        if (B.m != n)
        {
            throw new IllegalArgumentException("Matrix inner dimensions must agree.");
        }
        Matrix X = new Matrix(m, B.n);
        double[][] C = X.getArray();
        double[] Bcolj = new double[n];
        for (int j = 0; j < B.n; j++)
        {
            for (int k = 0; k < n; k++)
            {
                Bcolj[k] = B.A[k][j];
            }
            for (int i = 0; i < m; i++)
            {
                double[] Arowi = A[i];
                double s = 0;
                for (int k = 0; k < n; k++)
                {
                    s += Arowi[k] * Bcolj[k];
                }
                C[i][j] = s;
            }
        }
        return X;
    }
880920
public Matrix copy()
    {
        Matrix X = new Matrix(m, n);
        double[][] C = X.getArray();
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                C[i][j] = A[i][j];
            }
        }
        return X;
    }
319942
public IMatrix mul(IMatrix b) {
        IMatrix result = new IMatrix(rows, columns);
        mul(b, result);
        return result;
    }
1071817
public Matrix[] svd() {
		GMatrix m = (GMatrix) matrix.clone();
		int nrows = (int) getRowCount();
		int ncols = (int) getColumnCount();
		GMatrix u = new GMatrix(nrows, nrows);
		GMatrix s = new GMatrix(nrows, ncols);
		GMatrix v = new GMatrix(ncols, ncols);
		m.SVD(u, s, v);
		Matrix U = new VecMathDenseDoubleMatrix2D(u);
		Matrix S = new VecMathDenseDoubleMatrix2D(s);
		Matrix V = new VecMathDenseDoubleMatrix2D(v);
		return new Matrix[] { U, S, V };
	}
341033
public Matrix times(double s)
    {
        Matrix X = new Matrix(m, n);
        double[][] C = X.getArray();
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                C[i][j] = s * A[i][j];
            }
        }
        return X;
    }