net.sourceforge.jFuzzyLogic.FIS Java Examples

The following examples show how to use net.sourceforge.jFuzzyLogic.FIS. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EngineSoundSet.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
private void updateVolume (int track, FIS fuzzyEngine, float load, float rpm) {
	fuzzyEngine.setVariable("load", load);
	fuzzyEngine.setVariable("rpm", rpm);
	fuzzyEngine.evaluate();
	float volume = ((float)fuzzyEngine.getVariable("volume").getValue() / 100f);

	if (volume >= 0 && volume <= 1) {
		setVolume(track, volume * SoundManager.SfxVolumeMul);

		// dbg
		// if (track == 1 || track == 4) {
		// setVolume(track, (float)volume * SoundManager.SfxVolumeMul);
		// } else {
		// setVolume(track, 0);
		// }
		// dbg
	}
}
 
Example #2
Source File: TestCaseJfuzzy.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for membership function
 */
public void checkMembershipFunction(String title, String fclFile, String membershipFunctionFile) {
	int mem[][] = loadMembershipFile(membershipFunctionFile);

	FIS fis = FIS.load(fclFile);
	if (verbose) System.out.println(fis);
	FunctionBlock fb = fis.getFunctionBlock(null);

	for (int ind = 1; ind < mem.length; ind++) {
		double value = int100ToDouble(mem[ind][0]);

		fb.setVariable("inVar", value);

		int poor = doubleToInt100(fb.getVariable("inVar").getMembership("poor"));
		int good = doubleToInt100(fb.getVariable("inVar").getMembership("good"));
		int excellent = doubleToInt100(fb.getVariable("inVar").getMembership("excellent"));

		if (poor != mem[ind][1]) fail("Membership function " + title + ", poor(" + value + ") should be " + int100ToDouble(mem[ind][1]) + ", but it is " + int100ToDouble(poor));
		if (good != mem[ind][2]) fail("Membership function " + title + ", good(" + value + ") should be " + int100ToDouble(mem[ind][2]) + ", but it is " + int100ToDouble(good));
		if (excellent != mem[ind][3]) fail("Membership function " + title + ", excellent(" + value + ") should be " + int100ToDouble(mem[ind][3]) + ", but it is " + int100ToDouble(excellent));
	}
}
 
Example #3
Source File: TestCaseJfuzzy.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for membership function
 */
public void checkMembershipFunction(String title, FIS fis, String membershipFunctionFile) {
	Gpr.debug("Test");

	int mem[][] = loadMembershipFile(membershipFunctionFile);

	if (verbose) System.out.println(fis);
	FunctionBlock fb = fis.getFunctionBlock(null);

	for (int ind = 1; ind < mem.length; ind++) {
		double value = int100ToDouble(mem[ind][0]);

		fb.setVariable("inVar", value);

		int poor = doubleToInt100(fb.getVariable("inVar").getMembership("poor"));
		int good = doubleToInt100(fb.getVariable("inVar").getMembership("good"));
		int excellent = doubleToInt100(fb.getVariable("inVar").getMembership("excellent"));

		if (poor != mem[ind][1]) fail("Membership function " + title + ", poor(" + value + ") should be " + int100ToDouble(mem[ind][1]) + ", but it is " + int100ToDouble(poor));
		if (good != mem[ind][2]) fail("Membership function " + title + ", good(" + value + ") should be " + int100ToDouble(mem[ind][2]) + ", but it is " + int100ToDouble(good));
		if (excellent != mem[ind][3]) fail("Membership function " + title + ", excellent(" + value + ") should be " + int100ToDouble(mem[ind][3]) + ", but it is " + int100ToDouble(excellent));
	}
}
 
Example #4
Source File: TestCaseTipper.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method generating a string and parsing it
 */
@Test
public void testToString() {
	Gpr.debug("Test");

	// Load system
	String fileName = "tests/tipper.fcl";
	FIS fis = FIS.load(fileName, true);

	// Parse FCL code generated by fis.toString()
	FIS fis2;
	try {
		fis2 = FIS.createFromString(fis.toString(), false);
	} catch (RecognitionException e) {
		throw new RuntimeException("Could not parse FCL code generated by fis.toString(). This should never happen!!!");
	}

	// Compare both fis (should be identical)
	boolean ok = fis.toString().equals(fis2.toString());
	if (verbose) System.out.println("Are both fis equal?: " + ok);
	if (!ok) throw new RuntimeException("FCL code for both fis is not the same.");
}
 
Example #5
Source File: TestCaseTipper.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void createTxtFile() {
	// Load from 'FCL' file
	String fileName = "tests/tipper.fcl";
	FIS fis = FIS.load(fileName, true);

	// Show ruleset
	FunctionBlock functionBlock = fis.getFunctionBlock(null);

	// Set inputs
	for (double service = 0; service <= 10; service += 1.0)
		for (double food = 0; food <= 10; food += 1.0) {
			// Set inputs
			functionBlock.setVariable("service", service);
			functionBlock.setVariable("food", food);

			// Evaluate
			functionBlock.evaluate();

			// Get output
			double tip = functionBlock.getVariable("tip").getValue();

			// Show
			System.out.println(service + "\t" + food + "\t" + tip);
		}
}
 
Example #6
Source File: TestCaseJfuzzy.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method a fuzzy system that showed NA values due to 'Triangle' membership function bug
 * Bug report and FCL code by Shashankrao Wankhede
 */
@Test
public void testNAmembership() {
	Gpr.debug("Test");

	// FCL.debug = true;
	FIS fis = FIS.load("./tests/junit_shashankrao.fcl", true);
	if (verbose) System.out.println(fis);

	// This set of values used to produce a 'NaN' output
	double ra = 0.5;
	double ad = 0.0;
	fis.setVariable("ra", ra);
	fis.setVariable("ad", ad);
	fis.evaluate();

	// Right output should be 0.5
	double ta = fis.getVariable("ta").getValue();
	if (Double.isNaN(ta) || Double.isInfinite(ta) || (Math.abs(ta - 0.5) > EPSILON)) fail("System's output should be 0.5, but it's " + ta + "\n" + fis.getVariable("ta"));
}
 
Example #7
Source File: TestCaseCommandLine.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void test() {
	Gpr.debug("Test");

	// Prepare command line
	String fileName = "tests/tipper.fcl";
	String args[] = { "-noCharts", "-e", fileName, "8.5", "9" };

	// Run
	JFuzzyLogic jFuzzyLogic = new JFuzzyLogic(args);
	jFuzzyLogic.run();
	FIS fis = jFuzzyLogic.getFis();

	// Check input variables
	Assert.assertEquals(fis.getVariable("food").getValue(), 8.5, EPSILON);
	Assert.assertEquals(fis.getVariable("service").getValue(), 9, EPSILON);
}
 
Example #8
Source File: FuzzyTest.java    From paprika with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
    // Load from 'FCL' file
    String fileName = "fcl/Blob.fcl";
    FIS fis = FIS.load(fileName, true);

    if (fis == null) {
        System.err.println("Can't load file: '" + fileName + "'");
        System.exit(1);
    }

    // Get default function block
    FunctionBlock fb = fis.getFunctionBlock(null);
    JFuzzyChart.get().chart(fb);
    int [] lcom = {26,27,27,28,60,320,26,39}; // 25,40
    int [] nom = {17,17,18,19,17,21,27,22}; // 14.5,22
    int [] noa = {9,9,10,10,17,10,13,13}; // 8.5,13
    JFuzzyChart.get().chart(fb);
    for (int i = 0; i< lcom.length;i++){
        fb.setVariable("lack_of_cohesion_in_methods", lcom[i]);
        fb.setVariable("number_of_methods", nom[i]);
        fb.setVariable("number_of_attributes", noa[i]);
        fb.evaluate();
        JFuzzyChart.get().chart(fb.getVariable("res"),fb.getVariable("res").getDefuzzifier(),true);
        System.out.println("Res ("+lcom[i]+","+nom[i]+","+noa[i]+"): " + fb.getVariable("res").getValue());
    }
}
 
Example #9
Source File: CCQuery.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
public void executeFuzzy(boolean details) throws CypherException, IOException {
        Result result;
        try (Transaction ignored = graphDatabaseService.beginTx()) {
            String query = "MATCH (cl:Class) WHERE cl.class_complexity > " + high + " RETURN cl.app_key as app_key, cl.class_complexity as class_complexity";
            if(details){
                query += ",cl.name as full_name";
            }
            result = graphDatabaseService.execute(query);
            List<String> columns = new ArrayList<>(result.columns());
            columns.add("fuzzy_value");
            int cc;
            List<Map> fuzzyResult = new ArrayList<>();
            File fcf = new File(fclFile);
            //We look if the file is in a directory otherwise we look inside the jar
            FIS fis;
            if(fcf.exists() && !fcf.isDirectory()){
                fis = FIS.load(fclFile, false);
            }else{
                fis = FIS.load(getClass().getResourceAsStream(fclFile),false);
            }
            FunctionBlock fb = fis.getFunctionBlock(null);
            while(result.hasNext()){
                HashMap res = new HashMap(result.next());
                cc = (int) res.get("class_complexity");
                if(cc >= veryHigh){
                    res.put("fuzzy_value", 1);
                }else {
                    fb.setVariable("class_complexity",cc);
                    fb.evaluate();
                    res.put("fuzzy_value", fb.getVariable("res").getValue());
                }
                fuzzyResult.add(res);
                }
                queryEngine.resultToCSV(fuzzyResult,columns,"_CC.csv");
        }
}
 
Example #10
Source File: EngineSoundSet.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
public EngineSoundSet () {
	rpm = 0;
	gear = 1;

	//@off
	feIdle = FIS.load(Gdx.files.getFileHandle("data/audio/car-engine/fuzzy/engineVolIdle.fcl", FileType.Internal).read(), true);
	feOnLow = FIS.load(Gdx.files.getFileHandle("data/audio/car-engine/fuzzy/engineVolOnLow.fcl", FileType.Internal).read(), true);
	feOnMid= FIS.load(Gdx.files.getFileHandle("data/audio/car-engine/fuzzy/engineVolOnMid.fcl", FileType.Internal).read(), true);
	feOnHigh = FIS.load(Gdx.files.getFileHandle("data/audio/car-engine/fuzzy/engineVolOnHigh.fcl", FileType.Internal).read(), true);
	feOffLow = FIS.load(Gdx.files.getFileHandle("data/audio/car-engine/fuzzy/engineVolOffLow.fcl", FileType.Internal).read(), true);
	feOffMid= FIS.load(Gdx.files.getFileHandle("data/audio/car-engine/fuzzy/engineVolOffMid.fcl", FileType.Internal).read(), true);
	feOffHigh = FIS.load(Gdx.files.getFileHandle("data/audio/car-engine/fuzzy/engineVolOffHigh.fcl", FileType.Internal).read(), true);
	//@on
}
 
Example #11
Source File: TestCaseJfuzzy.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Verify that De Morgan's laws are OK
 */
void checkDeMorgan(FIS fis) {
	// De Morgan's laws test
	FunctionBlock fb = fis.getFunctionBlock(null);
	RuleBlock rb = fb.getRuleBlocks().values().iterator().next();
	List<Rule> rules = rb.getRules();
	Rule r1 = rules.get(0);
	Rule r2 = rules.get(1);
	Rule r3 = rules.get(2);
	Rule r4 = rules.get(3);

	r1.getDegreeOfSupport();

	// Set different values for 'food' and 'service'. Evaluate the system and show variables
	//		for( double service = 0.0, food = 1; service <= 10; service += 0.1 ) {
	for (double x1 = 0; x1 <= 1.0; x1 += 0.01) {
		for (double x2 = 0; x2 <= 1.0; x2 += 0.01) {
			// Evaluate system using these parameters
			fis.getVariable("x1").setValue(x1);
			fis.getVariable("x2").setValue(x2);
			fis.evaluate();

			// DeMorgan law: NOT(x1 IS small OR x2 IS small) == NOT(x1 IS small) AND NOT(x2 IS small)
			double diff = Math.abs(r1.getDegreeOfSupport() - r2.getDegreeOfSupport());
			if (diff > EPSILON) throw new RuntimeException(String.format("x1: %2.2f\tx2:%2.2f\t=> r1: %2.2f\tr2: %2.2f", x1, x2, r1.getDegreeOfSupport(), r2.getDegreeOfSupport()));

			// DeMorgan law: NOT(x1 IS small OR x2 IS small) == NOT(x1 IS small) AND NOT(x2 IS small)
			diff = Math.abs(r3.getDegreeOfSupport() - r4.getDegreeOfSupport());
			if (diff > EPSILON) throw new RuntimeException(String.format("x1: %2.6f\tx2:%2.6f\t=> r3: %2.6f\tr4: %2.6f", x1, x2, r3.getDegreeOfSupport(), r4.getDegreeOfSupport()));

		}
	}
}
 
Example #12
Source File: FuzzyEdgeOrchestrator.java    From EdgeCloudSim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void initialize() {
	numberOfHost=SimSettings.getInstance().getNumOfEdgeHosts();
	
	try {
		fis1 = FIS.createFromString(FCL_definition.fclDefinition1, false);
		fis2 = FIS.createFromString(FCL_definition.fclDefinition2, false);
		fis3 = FIS.createFromString(FCL_definition.fclDefinition3, false);
	} catch (RecognitionException e) {
		SimLogger.printLine("Cannot generate FIS! Terminating simulation...");
		e.printStackTrace();
		System.exit(0);
	}
}
 
Example #13
Source File: TestCaseTipper.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Test method 'tipper' fuzzy system
 */
@Test
public void testTipper() {
	Gpr.debug("Test");

	// Load tipper fuzzy system
	FIS fis = FIS.load("./tests/junit_tipper.fcl", true);
	FunctionBlock fb = fis.getFunctionBlock(null);

	// Load stored results
	int mem[][] = loadMembershipFile("./tests/junit_tipper.txt");

	// Compare running the system vs. stored results 
	for (int ind = 1; ind < mem.length; ind++) {
		// Get input variables from stores results
		double service = int100ToDOuble(mem[ind][0]);
		double food = int100ToDOuble(mem[ind][1]);

		// Set variables and run the system
		fb.setVariable("service", service);
		fb.setVariable("food", food);
		fb.evaluate();

		// Get output variable
		double tip = fb.getVariable("tip").getLatestDefuzzifiedValue();

		// Compare output variable to stored result
		if (doubleToInt100(tip) != mem[ind][2]) fail("Tipper output tip(service=" + service + ", food=" + food + ") should be " + int100ToDOuble(mem[ind][2]) + ", but it is " + tip);
	}
}
 
Example #14
Source File: TestCaseJfuzzy.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Check that De Morgan laws are correct for all AND/OR combinations
 */
@Test
public void testDeMorgan() {
	Gpr.debug("Test");

	if (verbose) System.out.println("Testing De Morgan's law: AND=MIN / OR=MAX");
	FIS fis = FIS.load("fcl/testDeMorgan_1.fcl");
	if (verbose) System.out.println(fis);
	checkDeMorgan(fis);

	if (verbose) System.out.println("Testing De Morgan's law: AND=PROD / OR=ASUM (a.k.a. PROB_OR)");
	fis = FIS.load("fcl/testDeMorgan_2.fcl");
	if (verbose) System.out.println(fis);
	checkDeMorgan(fis);

	if (verbose) System.out.println("Testing De Morgan's law: AND=BDIF / OR=BSUM");
	fis = FIS.load("fcl/testDeMorgan_3.fcl");
	if (verbose) System.out.println(fis);
	checkDeMorgan(fis);

	if (verbose) System.out.println("Testing De Morgan's law: AND=DMIN / OR=DMAX");
	fis = FIS.load("fcl/testDeMorgan_4.fcl");
	if (verbose) System.out.println(fis);
	checkDeMorgan(fis);

	if (verbose) System.out.println("Testing De Morgan's law: AND=NIPMIN / OR=NIPMAX");
	fis = FIS.load("fcl/testDeMorgan_5.fcl");
	if (verbose) System.out.println(fis);
	checkDeMorgan(fis);

	if (verbose) System.out.println("Testing De Morgan's law: AND=HAMACHER / OR=EINSTEIN");
	fis = FIS.load("fcl/testDeMorgan_6.fcl");
	if (verbose) System.out.println(fis);
	checkDeMorgan(fis);
}
 
Example #15
Source File: TestCaseTipper.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void test() {
	Gpr.debug("Test");

	// Load from 'FCL' file
	String fileName = "tests/tipper.fcl";
	FIS fis = FIS.load(fileName, true);

	// Show ruleset
	FunctionBlock functionBlock = fis.getFunctionBlock(null);

	// Read results file
	String lines[] = Gpr.readFile("tests/tipper.txt").split("\n");

	// Iterate
	for (String line : lines) {
		// Parse line
		String recs[] = line.split("\t");

		double service = Gpr.parseDoubleSafe(recs[0]);
		double food = Gpr.parseDoubleSafe(recs[1]);
		double tip = Gpr.parseDoubleSafe(recs[2]);

		// Set inputs
		functionBlock.setVariable("service", service);
		functionBlock.setVariable("food", food);

		// Evaluate
		functionBlock.evaluate();

		// Get output
		double tipEv = functionBlock.getVariable("tip").getValue();

		// Show
		Assert.assertEquals(tip, tipEv, EPSILON);
	}
}
 
Example #16
Source File: BLOBQuery.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
public void executeFuzzy(boolean details) throws CypherException, IOException {
        Result result;
        try (Transaction ignored = graphDatabaseService.beginTx()) {
            String query = "MATCH (cl:Class) WHERE cl.lack_of_cohesion_in_methods >" + high_lcom + " AND cl.number_of_methods > " + high_nom + " AND cl.number_of_attributes > " + high_noa + " RETURN cl.app_key as app_key,cl.lack_of_cohesion_in_methods as lack_of_cohesion_in_methods,cl.number_of_methods as number_of_methods, cl.number_of_attributes as number_of_attributes";
            if(details){
                query += ",cl.name as full_name";
            }
            result = graphDatabaseService.execute(query);
            List<String> columns = new ArrayList<>(result.columns());
            columns.add("fuzzy_value");
            int lcom,noa,nom;
            List<Map> fuzzyResult = new ArrayList<>();
            File fcf = new File(fclFile);
            //We look if the file is in a directory otherwise we look inside the jar
            FIS fis;
            if(fcf.exists() && !fcf.isDirectory()){
                fis = FIS.load(fclFile, false);
            }else{
                fis = FIS.load(getClass().getResourceAsStream(fclFile),false);
            }
            FunctionBlock fb = fis.getFunctionBlock(null);
            while(result.hasNext()){
                HashMap res = new HashMap(result.next());
                lcom = (int) res.get("lack_of_cohesion_in_methods");
                noa = (int) res.get("number_of_attributes");
                nom = (int) res.get("number_of_methods");
                if(lcom >= veryHigh_lcom && noa >= veryHigh_noa && nom >= veryHigh_nom){
                    res.put("fuzzy_value", 1);
                }else {
                    fb.setVariable("lack_of_cohesion_in_methods",lcom);
                    fb.setVariable("number_of_attributes",noa);
                    fb.setVariable("number_of_methods",nom);
                    fb.evaluate();
                    res.put("fuzzy_value", fb.getVariable("res").getValue());
                }
                fuzzyResult.add(res);
                }
                queryEngine.resultToCSV(fuzzyResult,columns,"_BLOB.csv");
        }
}
 
Example #17
Source File: TestExecutioner.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<Double> execute(String fileName, String[] inputVariables, int steps, int stepSize) {

		// Load FIS
		FIS fis = FIS.load(fileName, false);
		if( fis == null ) { // Error while loading?
			System.err.println("Can't load file: '" + fileName + "'");
			return null;
		}

		FunctionBlock functionBlock = fis.getFunctionBlock(null);

		// Time recording
		List<Double> timeRecords = new ArrayList<Double>();
		long startTime;
		int curStep = 0;

		// Test
		for( int i = 0; i <= steps; i++, curStep += stepSize ) {
			startTime = System.currentTimeMillis();

			for( int j = 0; j <= curStep; j++ ) {
				// Set inputs
				for( int k = 0; k < inputVariables.length; k++ )
					functionBlock.setVariable(inputVariables[k], Math.random() * 5);

				// Evaluate fuzzy set
				functionBlock.evaluate();
			}
			timeRecords.add(new Double(System.currentTimeMillis() - startTime));
			if( debug ) Gpr.debug("Evaluate " + fileName + "\ti:" + i + "\tcurStep: " + curStep);
		}
		return timeRecords;
	}
 
Example #18
Source File: TestCaseJfuzzy.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link net.sourceforge.jFuzzyLogic.FIS#load(java.lang.String)}.
 */
@Test
public void testFileParsing1() {
	Gpr.debug("Test");

	FIS fis = FIS.load("./tests/junit1.fcl", true);
	if (verbose) System.out.println(fis);
	separator();
}
 
Example #19
Source File: JDialogFis.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void init(FIS fis, int width, int height) {
	setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); // The program may still run when the window is closed (that's why we don't use JFrame.EXIT_ON_CLOSE)
	BoxLayout layout = new BoxLayout(getContentPane(), 0);
	getContentPane().setLayout(layout);
	pack();
	panel = new JPanelFis(fis);
	setSize(width, height);
	setLayout(new BorderLayout());
	getContentPane().add(panel, BorderLayout.CENTER);
	setVisible(true);
}
 
Example #20
Source File: TestCaseJfuzzy.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link net.sourceforge.jFuzzyLogic.FIS#load(java.lang.String)}.
 */
@Test
public void testFileParsing2() {
	Gpr.debug("Test");

	FIS fis = FIS.load("./tests/junit2.fcl", true);
	if (verbose) System.out.println(fis);
	separator();
}
 
Example #21
Source File: TestCaseJfuzzy.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link net.sourceforge.jFuzzyLogic.FIS#load(java.lang.String)}.
 */
@Test
public void testFileParsing3() {
	Gpr.debug("Test");

	FIS fis = FIS.load("./tests/junit3.fcl", true);
	if (verbose) System.out.println(fis);
	separator();
}
 
Example #22
Source File: TestCaseJfuzzy.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link net.sourceforge.jFuzzyLogic.FIS#load(java.lang.String)}.
 */
@Test
public void testFileParsing4() {
	Gpr.debug("Test");

	FIS fis = FIS.load("./tests/junit4.fcl", true);
	if (verbose) System.out.println(fis);
	separator();
}
 
Example #23
Source File: TestCaseJfuzzy.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Test method a fuzzy system that uses functions
 */
@Test
public void testFunctions() {
	Gpr.debug("Test");

	// Load tipper fuzzy system
	FIS fis = FIS.load("./tests/junit_functions.fcl", true);
	FunctionBlock fb = fis.getFunctionBlock(null);

	// Load stored results
	int mem[][] = loadMembershipFile("./tests/junit_functions.txt");

	// Compare running the system vs. stored results
	for (int ind = 0; ind < mem.length; ind++) {
		// Get input variables from stores results
		double inVar = int100ToDouble(mem[ind][0]);

		// Set variables and run the system
		fb.setVariable("inVar", inVar);
		fb.evaluate();

		// Get output variable
		double outVar = fb.getVariable("outVar").getLatestDefuzzifiedValue();

		// Compare output variable to stored result
		if (doubleToInt100(outVar) != mem[ind][4]) fail("Output outVar(inVar=" + inVar + ") should be " + int100ToDouble(mem[ind][4]) + ", but it is " + outVar);
	}
}
 
Example #24
Source File: TestCaseJfuzzy.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Test method for membership function
 */
@Test
public void testMembershipFunctionOnLine4() {
	Gpr.debug("Test");

	FIS fis = FIS.load("./tests/on_line_variable.fcl");

	double i = 4.0;
	fis.setVariable("inputZeroMin", i - 1.0);
	fis.setVariable("inputZeroMed", i);
	fis.setVariable("inputZeroMax", i + 1.0);

	checkMembershipFunction("Online", fis, "./tests/on_line_variable_4.txt");
}
 
Example #25
Source File: TestCaseJfuzzy.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Test method for membership function
 */
@Test
public void testMembershipFunctionOnLine5() {
	Gpr.debug("Test");

	FIS fis = FIS.load("./tests/on_line_variable.fcl");

	double i = 5.0;
	fis.setVariable("inputZeroMin", i - 1.0);
	fis.setVariable("inputZeroMed", i);
	fis.setVariable("inputZeroMax", i + 1.0);

	checkMembershipFunction("Online", fis, "./tests/on_line_variable_5.txt");
}
 
Example #26
Source File: FuzzyController.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void reload(String str) {
	FIS newfis;
	try {
		newfis = FIS.createFromString(str, true);
		fis = newfis;
		fisString = str;
		//          functionBlock = fis.getFunctionBlock(null);
		init();
	} catch(RecognitionException ex) {
		Logger.getLogger(FuzzyController.class.getName()).log(Level.SEVERE, null, ex);
	}

}
 
Example #27
Source File: TestCaseJfuzzy.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Test method for membership function
 */
@Test
public void testMembershipFunctionOnLine6() {
	Gpr.debug("Test");

	FIS fis = FIS.load("./tests/on_line_variable.fcl");

	double i = 6.0;
	fis.setVariable("inputZeroMin", i - 1.0);
	fis.setVariable("inputZeroMed", i);
	fis.setVariable("inputZeroMax", i + 1.0);

	checkMembershipFunction("Online", fis, "./tests/on_line_variable_6.txt");
}
 
Example #28
Source File: FuzzyDemo.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
void initFisDebugPanel() {
	// Create a plot
	if (fisPanel != null) {
		System.out.println(" Remove existing fis panel");
		fuzzyLayout.getTabPanel().remove(fisPanel);
	}
	FIS fis = fuzzyController.getFis();
	List<Variable> list = fuzzyController.getVariables();
	fisPanel = new DemoPanelFis(fuzzyController.getVariables(),
			list.size(), 1);
	fuzzyLayout.getTabPanel().add("Graphs", fisPanel);
}
 
Example #29
Source File: HeavyBroadcastReceiverQuery.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
public void executeFuzzy(boolean details) throws CypherException, IOException {
        Result result;
        try (Transaction ignored = graphDatabaseService.beginTx()) {
            String query = "MATCH (c:Class{is_broadcast_receiver:true})-[:CLASS_OWNS_METHOD]->(m:Method{name:'onReceive'}) WHERE m.number_of_instructions > "+high_noi+" AND m.cyclomatic_complexity>"+high_cc+" return m.app_key as app_key,m.cyclomatic_complexity as cyclomatic_complexity, m.number_of_instructions as number_of_instructions";
            if(details){
                query += ",m.full_name as full_name";
            }
            result = graphDatabaseService.execute(query);
            List<String> columns = new ArrayList<>(result.columns());
            columns.add("fuzzy_value");
            int noi,cc;
            List<Map> fuzzyResult = new ArrayList<>();
            File fcf = new File(fclFile);
            //We look if the file is in a directory otherwise we look inside the jar
            FIS fis;
            if(fcf.exists() && !fcf.isDirectory()){
                fis = FIS.load(fclFile, false);
            }else{
                fis = FIS.load(getClass().getResourceAsStream(fclFile),false);
            }
            FunctionBlock fb = fis.getFunctionBlock(null);
            while(result.hasNext()){
                HashMap res = new HashMap(result.next());
                cc = (int) res.get("cyclomatic_complexity");
                noi = (int) res.get("number_of_instructions");
                if(cc >= veryHigh_cc && noi >= veryHigh_noi){
                    res.put("fuzzy_value", 1);
                }else {
                    fb.setVariable("cyclomatic_complexity",cc);
                    fb.setVariable("number_of_instructions",noi);
                    fb.evaluate();
                    res.put("fuzzy_value", fb.getVariable("res").getValue());
                }
                fuzzyResult.add(res);
                }
                queryEngine.resultToCSV(fuzzyResult,columns,"_HBR.csv");
        }
}
 
Example #30
Source File: TestTipperJava.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Show animation
 * @param fis
 * @throws Exception
 */
static void animateFis(FIS fis) throws Exception {
	if (JFuzzyChart.UseMockClass) {
		Gpr.debug("Using mock class");
		return; // Nothing done
	}

	// Create a plot
	JDialogFis jdf = new JDialogFis(fis, 800, 600);

	// Set different values for 'food' and 'service'. Evaluate the system and show variables
	//		for( double service = 0.0, food = 1; service <= 10; service += 0.1 ) {
	for (double service = 0.0, food = 1; service <= 10; service += 0.1) {
		food = service;
		// Evaluate system using these parameters
		fis.getVariable("service").setValue(service);
		fis.getVariable("food").setValue(food);
		fis.evaluate();

		// Print result & update plot
		System.out.println(String.format("Service: %2.2f\tfood:%2.2f\t=> tip: %2.2f %%", service, food, fis.getVariable("tip").getValue()));
		jdf.repaint();

		// Small delay
		Thread.sleep(100);
	}

}