use of edu.cmu.tetrad.util.PermutationGenerator in project tetrad by cmu-phil.
the class TestChoiceGenerator method testPrintPermutationGenerator.
@Test
public void testPrintPermutationGenerator() {
PermutationGenerator gen = new PermutationGenerator(4);
int count = 0;
while (gen.next() != null) {
count++;
}
assertEquals(24, count);
}
use of edu.cmu.tetrad.util.PermutationGenerator in project tetrad by cmu-phil.
the class BinaryFunctionUtils method equalsUnderSomePermutation.
/**
* @return true if f1 is equal to f2 under some column permutation.
*/
private boolean equalsUnderSomePermutation(BinaryFunction f1, BinaryFunction f2) {
PermutationGenerator pg = new PermutationGenerator(f1.getNumArgs());
int[] permutation;
while ((permutation = pg.next()) != null) {
if (equalsUnderPermutation(f1, f2, permutation)) {
return true;
}
}
return false;
}
use of edu.cmu.tetrad.util.PermutationGenerator in project tetrad by cmu-phil.
the class Lingam method estimateCausalOrder.
// ================================PUBLIC METHODS========================//
private CausalOrder estimateCausalOrder(DataSet dataSet) {
TetradMatrix X = dataSet.getDoubleData();
FastIca fastIca = new FastIca(X, 30);
fastIca.setVerbose(false);
FastIca.IcaResult result = fastIca.findComponents();
TetradMatrix W = result.getW().transpose();
System.out.println("W = " + W);
PermutationGenerator gen1 = new PermutationGenerator(W.rows());
int[] perm1 = new int[0];
double sum1 = Double.POSITIVE_INFINITY;
int[] choice1;
while ((choice1 = gen1.next()) != null) {
double sum = 0.0;
for (int i = 0; i < W.rows(); i++) {
final double c = W.get(i, choice1[i]);
sum += 1.0 / abs(c);
}
if (sum < sum1) {
sum1 = sum;
perm1 = Arrays.copyOf(choice1, choice1.length);
}
}
TetradMatrix WTilde = W.getSelection(perm1, perm1);
System.out.println("WTilde before normalization = " + WTilde);
for (int j = 0; j < WTilde.columns(); j++) {
for (int i = j; i < WTilde.rows(); i++) {
WTilde.set(i, j, WTilde.get(i, j) / WTilde.get(j, j));
}
}
System.out.println("WTilde after normalization = " + WTilde);
final int m = dataSet.getNumColumns();
TetradMatrix B = TetradMatrix.identity(m).minus(WTilde.transpose());
System.out.println("B = " + B);
PermutationGenerator gen2 = new PermutationGenerator(B.rows());
int[] perm2 = new int[0];
double sum2 = Double.POSITIVE_INFINITY;
int[] choice2;
while ((choice2 = gen2.next()) != null) {
double sum = 0.0;
for (int i = 0; i < W.rows(); i++) {
for (int j = i; j < W.rows(); j++) {
final double c = B.get(choice2[i], choice2[j]);
sum += c * c;
}
}
if (sum < sum2) {
sum2 = sum;
perm2 = Arrays.copyOf(choice2, choice2.length);
}
}
TetradMatrix BTilde = B.getSelection(perm2, perm2);
System.out.println("BTilde = " + BTilde);
return new CausalOrder(perm2);
}
Aggregations