|
Test.java
|
package test; import hlt.math.fuzzy.*; import hlt.language.util.ArrayList; import hlt.language.util.IntArrayList; import hlt.language.util.DoubleArrayList; public class Test { public static void main (String[] args) { // FuzzyMatrix.setFuzzyAlgebra("product"); FuzzyMatrix.precision = "%4.1f "; // testFuzzySetOf(); // testFuzzyMatrix(); // testSquareFuzzyMatrix(); testSignatureSimilarity(); } // public static void testFuzzyMatrix () // { // double[][] d = { { 0.0, 0.1, 0.2, 0.3 } // , { 0.4, 0.5, 0.6, 0.7 } // , { 0.8, 0.9, 1.0, 1.0 } // }; // System.out.println("TESTING FuzzyMatrix\n"); // FuzzyMatrix D = new FuzzyMatrix(d); // shares the actual array d, not a copy // // Could also be: // // FuzzyMatrix D = new FuzzyMatrix(d,true); // true: to copy and ensure only values within [0.0,1.0] // D.show(); // System.out.println(); // System.out.println("random 5x8 fuzzy matrix A:"); // FuzzyMatrix A = FuzzyMatrix.random(5,8); // A.show(); // System.out.println(); // System.out.println("Its transpose B:"); // FuzzyMatrix B = A.transpose(); // B.show(); // System.out.println(); // System.out.println("A plus transpose(B) (i.e., itself):"); // A.plus(B.transpose()).show(); // System.out.println(); // System.out.println("A times transpose(A) (a 3x3 matrix):"); // A.times(A.transpose()).show(); // System.out.println(); // System.out.println("transpose(A) times A (a 5x5 matrix):"); // A.transpose().times(A).show(); // System.out.println(); // // System.out.println("is A times transpose(B) equal? (should be false in general):"); // // System.out.println(A.plus(A).eq(B.transpose().plus(A))); // // System.out.println(); // } // public static void testSquareFuzzyMatrix () // { // System.out.println("TESTING SquareFuzzyMatrix\n"); // // System.out.println("the 6x6 identity I:"); // // SquareFuzzyMatrix I = SquareFuzzyMatrix.identity(6); // // I.show(); // // System.out.println(); // // System.out.println("a 6x6 zero matrix:"); // SquareFuzzyMatrix M = new SquareFuzzyMatrix(6); // // M.show(); // // System.out.println(); // // // See run in test1.txt // // System.out.println("a 6x6 matrix:"); // // // System.out.println("adding to it some pairs:"); // // M.set(1,2,.2) // // .set(1,3,.4) // // .set(3,4,.8) // // .set(3,5,.6) // // .set(4,5,.9) // // .set(4,6,.7); // // See run in test2.txt // System.out.println("a 6x6 matrix:"); // // System.out.println("adding to it some pairs:"); // M.set(1,2,.3) // .set(1,4,.5) // .set(2,4,1.)//.set(2,4,.7) // .set(2,5,.4) // .set(4,6,.2); // // M.set(1,2,1.0) // // .set(1,3,1.0) // // .set(3,4,1.0) // // .set(3,5,1.0) // // .set(4,5,1.0) // // .set(4,6,1.0); // // M.set(1,2,.2) // // .set(1,3,.4) // // .set(3,4,.8) // // .set(3,5,.6) // // .set(4,5,.9) // // .set(4,6,.7); // M.show(); // System.out.println(); // // System.out.println("and its set of values:"); // // System.out.println(M.getValues()); // // System.out.println(); // // System.out.println("the reflexive closure of the above:"); // // M.i_reflexive_closure(); // // M.show(); // // System.out.println(); // // System.out.println("the symmetric closure of the above:"); // // M.i_symmetric_closure(); // // M.show(); // // System.out.println(); // // System.out.println("the transitive closure of the above:"); // // M.i_transitive_closure(); // // M.show(); // // System.out.println(); // // System.out.println("the similarity closure of the above (should be the same):"); // SquareFuzzyMatrix result; // // FuzzyMatrix.setFuzzyAlgebra("luka"); // // System.out.println("its similarity closure with lukasievicz:"); // // result = M.similarity_closure(); // // result.show(); // // System.out.println(); // // System.out.println("and its set of values:"); // // System.out.println(result.getValues()); // // System.out.println(); // // FuzzyMatrix.setFuzzyAlgebra("product"); // // System.out.println("its similarity closure with probabilistic (product):"); // // result = M.similarity_closure(); // // result.show(); // // System.out.println(); // // System.out.println("and its set of values:"); // // System.out.println(result.getValues()); // // System.out.println(); // // FuzzyMatrix.setFuzzyAlgebra("maxmin"); // System.out.println("its similarity closure with max/min:"); // result = M.similarity_closure(); // result.show(); // System.out.println(); // DoubleArrayList values = result.getValues(); // System.out.println("and its set of values:"); // System.out.println(values); // System.out.println(); // System.out.println("and its fuzzy partitions:"); // for (int k=0; k<values.size(); k++) // { // double threshold = values.get(k); // System.out.println("at or over threshold "+threshold); // IntArrayList[] classes = result.partition(threshold); // for (int i=0; i<result.n(); i++) // System.out.println("["+i+"] = "+classes[i]); // System.out.println(); // } // } public static void testSignatureSimilarity () { Functor a = new Functor("a",0); Functor b = new Functor("b",1); Functor e = new Functor("e",2); Functor f = new Functor("f",3); Functor g = new Functor("g",4); Functor h = new Functor("h",5); Functor[] functors = { a, b, e, f, g, h }; double[][] data = // // 0 1 2 3 4 5 // /* 0 */ { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } // /* 1 */ , { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 } // /* 2 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } // /* 3 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } // /* 4 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } // /* 5 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } // 0 1 2 3 4 5 /* 0 */ { { 0.0, 0.3, 0.0, 0.5, 0.0, 0.0 } /* 1 */ , { 0.0, 0.0, 0.0, 1.0, 0.4, 0.0 } /* 2 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } /* 3 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.2 } /* 4 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } /* 5 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } // // 0 1 2 3 4 5 // /* 0 */ { { 0.0, 0.2, 0.4, 0.0, 0.0, 0.0 } // /* 1 */ , { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 } // /* 2 */ , { 0.0, 0.0, 0.0, 0.8, 0.6, 0.0 } // /* 3 */ , { 0.0, 0.0, 0.0, 0.0, 0.9, 0.7 } // /* 4 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } // /* 5 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } }; SignatureSimilarity sim = new SignatureSimilarity(functors,data); System.out.print("a signature of 6 functors: {"); for (int i=0; i<sim.m(); i++) System.out.print(sim.functor(i)+(i<sim.m()-1?", ":" }")); System.out.println("\n"); System.out.println("a 6x6 similarity on this signature:"); sim.show(); DoubleArrayList values = sim.getValues(); System.out.println("and its set of values:"); System.out.println(values); System.out.println(); System.out.println("and its fuzzy partitions:\n"); for (int k=0; k<values.size(); k++) { double threshold = values.get(k); System.out.print(">= "+threshold+": "); IntArrayList[] indexClasses = sim.partition(threshold); // // by indices: // System.out.println("by indices:"); // for (int i=0; i<sim.m(); i++) // System.out.println("["+i+"] = "+indexClasses[i]); // System.out.println(); // // by names: // System.out.println("by names:"); ArrayList[] nameClasses = new ArrayList[sim.m()]; for (int i=0; i<sim.m(); i++) { ArrayList nameClass = new ArrayList(); for (int j=0; j<indexClasses[i].size(); j++) nameClass.add(sim.functor(indexClasses[i].get(j)).name()); nameClasses[i] = nameClass; } // for (int i=0; i<sim.m(); i++) // System.out.println("["+sim.functor(i).name()+"] = "+setForm(nameClasses[i])); // System.out.println(); ArrayList dejavu = new ArrayList(sim.m()); for (int i=0; i<sim.m(); i++) { ArrayList classNames = nameClasses[i]; if (!dejavu.contains(classNames)) { System.out.print(" "+setForm(classNames)); dejavu.add(classNames); } } System.out.println(); } } private static String setForm (ArrayList list) { StringBuilder buf = new StringBuilder("{"); int size = list.size(); for (int i=0; i<size; i++) buf.append(list.get(i)+(i==size-1?"":",")); return (buf.append("}")).toString(); } }
This file was generated on Wed Jun 06 09:40:31 CEST 2018 from file Test.java
by the hlt.language.tools.Hilite Java tool written by Hassan Aït-Kaci