home › Forums › # Technical Support › need for helping
- This topic has 6 replies, 3 voices, and was last updated 8 years, 8 months ago by
Juan Rada-Vilela (admin).
-
AuthorPosts
-
January 2, 2015 at 01:25 #1585
Unknown
MemberHi Juan, Happy new year
First of all, developing jFuzzyLite is a great and beneficial work and I friendly do thank you for that. I tend to develop an application in Android, in brief that must receive some of raw data form different sensors. then it must have an button that when we click on it, do fuzzy process on provided sensory data. For this aim, I wanna use jFuuzyLite by Intellij IDEA. at this point I can get your library version 4 from this site and then I attached included library, jfuzzylite.jar, into my project. But, I am a bit confused because there aren’t any step-by-step tutorial for using jFuzzzyLite. In summary I have some question:1- as i saw in Forums and also in your sample java code, it must be wrapped in main method of java class, so how we can use it in android in for of simple class without main method?
2- if I put a simple Button to call this class how I can get the result of process and show it for example in a TextView?
3- Are there any tutorial to use jFuzzyLite for even simple example?I know you are on holiday now, but I really need your help. Please accept my apologize.
any answer to my question would be appreciated.January 2, 2015 at 01:37 #1586Unknown
MemberIt’s my first try to use your simple sample of jFuzzyLite, but to tell you the truth, I don’t have any knowledge for example why different methods have been used? and, what is the functionality of each one?
///////////
package com.example.FirstFuzzy;import android.app.Activity;
import android.os.Bundle;
import com.fuzzylite.Engine;
import com.fuzzylite.FuzzyLite;
import com.fuzzylite.Op;
import com.fuzzylite.norm.s.Maximum;
import com.fuzzylite.norm.t.Minimum;
import com.fuzzylite.rule.Rule;
import com.fuzzylite.rule.RuleBlock;
import com.fuzzylite.term.Triangle;
import com.fuzzylite.variable.InputVariable;
import com.fuzzylite.variable.OutputVariable;public class MyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MyFuzzy myFuzzy=new MyFuzzy();
try {
Engine engine = new Engine(“simple-dimmer”);
InputVariable ambient = new InputVariable();
ambient.setName(“Ambient”);
ambient.setRange(0.000, 1.000);
ambient.addTerm(new Triangle(“DARK”, 0.000, 0.500));
ambient.addTerm(new Triangle(“MEDIUM”, 0.250, 0.750));
ambient.addTerm(new Triangle(“BRIGHT”, 0.500, 1.000));
engine.addInputVariable(ambient);OutputVariable power = new OutputVariable();
power.setName(“Power”);
power.setRange(0.000, 1.000);
power.setDefaultValue(Double.NaN);
power.addTerm(new Triangle(“LOW”, 0.000, 0.500));
power.addTerm(new Triangle(“MEDIUM”, 0.250, 0.750));
power.addTerm(new Triangle(“HIGH”, 0.500, 1.000));
engine.addOutputVariable(power);RuleBlock ruleBlock = new RuleBlock();
ruleBlock.addRule(Rule.parse(“if Ambient is DARK then Power is HIGH”, engine));
ruleBlock.addRule(Rule.parse(“if Ambient is MEDIUM then Power is MEDIUM”, engine));
ruleBlock.addRule(Rule.parse(“if Ambient is BRIGHT then Power is LOW”, engine));
engine.addRuleBlock(ruleBlock);//No Conjunction or Disjunction is needed
ruleBlock.setConjunction(new Minimum());
ruleBlock.setDisjunction(new Maximum());
engine.configure(“”, “”, “AlgebraicProduct”, “AlgebraicSum”, “Centroid”);StringBuilder status = new StringBuilder();
if (!engine.isReady(status))
throw new RuntimeException(“Engine not ready. ” +
“The following errors were encountered:\n” + status.toString());for (int i = 0; i < 50; ++i) {
double light = ambient.getMinimum() + i * (ambient.range() / 50);
ambient.setInputValue(light);
engine.process();
FuzzyLite.logger().info(String.format(
“Ambient.input = %s -> Power.output = %s”,
Op.str(light), Op.str(power.defuzzify())));
}
}catch (Exception e)
{
e.printStackTrace();
}
}
}//////////////////////
any help can be appreciated.January 5, 2015 at 10:05 #1594Unknown
MemberIsn’t anyone else who has an experiece to help me? I really must solve my problem as soon as possible…
Any answer would be appreciated.January 5, 2015 at 10:45 #1595Unknown
MemberHi soroushojagh,
I think you can just take the samples, which are presented in main functions and put it inside any other method.
For example an event method which is triggerd by an button action.January 5, 2015 at 19:54 #1597Unknown
MemberHi verte,
thanks a lot for your tip, but really I don’t know how I can show the fuzzy process result for example in a Toast, or TextView? can you explain how I can do it? I attached my sample code before, can you explain where I can put methods for showing the results?January 6, 2015 at 03:53 #1601Unknown
MemberIn your code you have:
engine.process(); FuzzyLite.logger().info(String.format( “Ambient.input = %s -> Power.output = %s”, Op.str(light), Op.str(power.defuzzify())));
Instead of using the logger, you can concatenate the the outputs in a String and show it afer your for loop
for (int i = 0; i < 50; ++i) { ... } [showTextView(outPutString);]
January 6, 2015 at 08:24 #1602Juan Rada-Vilela (admin)
KeymasterHi,
thanks for your responses. As vurtue mentions, use the UI component instead of the logger.
In addition, you should have the engine as a member of your class such that you can retrieve the engine later in a different method. For example,
public class MyActivity extends Activity { private Engine engine; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MyFuzzy myFuzzy=new MyFuzzy(); try { engine = new Engine(“simple-dimmer”); InputVariable ambient = new InputVariable(); ambient.setName(“Ambient”); ... } public void someOtherMethodCalledByAnEvent(){ //A button click? engine.getInputVariable("Ambient").setInputValue(someUiComponent.getDoubleValue()); engine.process(); double output = engine.getOutputVariable("Power").defuzzify(); anotherUiComponent.setText(Op.str(output)); }
I hope this helps.
Cheers.
-
AuthorPosts
- You must be logged in to reply to this topic.