Question: Modify the code so that can input 3 value to predict tip, other than food quality and service level. help please import generic.Input; import generic.Output;

Modify the code so that can input 3 value to predict tip, other than food quality and service level. help please

import generic.Input; import generic.Output; import generic.Tuple; import tools.JMathPlotter; import type1.sets.T1MF_Gauangle; import type1.sets.T1MF_Gaussian; import type1.sets.T1MF_Interface; import type1.sets.T1MF_Triangular; import type1.system.T1_Antecedent; import type1.system.T1_Consequent; import type1.system.T1_Rule; import type1.system.T1_Rulebase;

public class SimpleT1FLS { Input food, service; //the inputs to the FLS Output tip; //the output of the FLS T1_Rulebase rulebase; //the rulebase captures the entire FLS public SimpleT1FLS() { //Define the inputs food = new Input("Food Quality", new Tuple(0,10)); //a rating given by a person between 0 and 10 service = new Input("Service Level", new Tuple(0,10)); //a rating given by a person between 0 and 10 tip = new Output("Tip", new Tuple(0,30)); //a percentage for the tip

//Set up the membership functions (MFs) for each input and output T1MF_Triangular badFoodMF = new T1MF_Triangular("MF for bad food",0.0, 0.0, 10.0); T1MF_Triangular greatFoodMF = new T1MF_Triangular("MF for great food",0.0, 10.0, 10.0);

T1MF_Gauangle unfriendlyServiceMF = new T1MF_Gauangle("MF for unfriendly service",0.0, 0.0, 6.0); T1MF_Gauangle okServiceMF = new T1MF_Gauangle("MF for ok service",2.5, 5.0, 7.5); T1MF_Gauangle friendlyServiceMF = new T1MF_Gauangle("MF for friendly service",4.0, 10.0, 10.0);

T1MF_Gaussian lowTipMF = new T1MF_Gaussian("Low tip", 0.0, 6.0); T1MF_Gaussian mediumTipMF = new T1MF_Gaussian("Medium tip", 15.0, 6.0); T1MF_Gaussian highTipMF = new T1MF_Gaussian("High tip", 30.0, 6.0);

//Set up the antecedents and consequents - note how the inputs are associated... T1_Antecedent badFood = new T1_Antecedent("BadFood",badFoodMF, food); T1_Antecedent greatFood = new T1_Antecedent("GreatFood",greatFoodMF, food);

T1_Antecedent unfriendlyService = new T1_Antecedent("UnfriendlyService",unfriendlyServiceMF, service); T1_Antecedent okService = new T1_Antecedent("OkService",okServiceMF, service); T1_Antecedent friendlyService = new T1_Antecedent("FriendlyService",friendlyServiceMF, service);

T1_Consequent lowTip = new T1_Consequent("LowTip", lowTipMF, tip); T1_Consequent mediumTip = new T1_Consequent("MediumTip", mediumTipMF, tip); T1_Consequent highTip = new T1_Consequent("HighTip", highTipMF, tip);

//Set up the rulebase and add rules rulebase = new T1_Rulebase(6); rulebase.addRule(new T1_Rule(new T1_Antecedent[]{badFood, unfriendlyService}, lowTip)); rulebase.addRule(new T1_Rule(new T1_Antecedent[]{badFood, okService}, lowTip)); rulebase.addRule(new T1_Rule(new T1_Antecedent[]{badFood, friendlyService}, mediumTip)); rulebase.addRule(new T1_Rule(new T1_Antecedent[]{greatFood, unfriendlyService}, lowTip)); rulebase.addRule(new T1_Rule(new T1_Antecedent[]{greatFood, okService}, mediumTip)); rulebase.addRule(new T1_Rule(new T1_Antecedent[]{greatFood, friendlyService}, highTip)); //just an example of setting the discretisation level of an output - the usual level is 100 tip.setDiscretisationLevel(50); //get some outputs getTip(7,8); //plot some sets, discretizing each input into 100 steps. plotMFs("Food Quality Membership Functions", new T1MF_Interface[]{badFoodMF, greatFoodMF}, food.getDomain(), 100); plotMFs("Service Level Membership Functions", new T1MF_Interface[]{unfriendlyServiceMF, okServiceMF, friendlyServiceMF}, service.getDomain(), 100); plotMFs("Level of Tip Membership Functions", new T1MF_Interface[]{lowTipMF, mediumTipMF, highTipMF}, tip.getDomain(), 100); //plot control surface //do either height defuzzification (false) or centroid d. (true) plotControlSurface(true, 100, 100); //print out the rules System.out.println(" "+rulebase); } private void getTip(double foodQuality, double serviceLevel) { //first, set the inputs food.setInput(foodQuality); service.setInput(serviceLevel); /ow execute the FLS and print output System.out.println("The food was: "+food.getInput()); System.out.println("The service was: "+service.getInput()); System.out.println("Using height defuzzification, the FLS recommends a tip of" + "tip of: "+rulebase.evaluate(0).get(tip)); System.out.println("Using centroid defuzzification, the FLS recommends a tip of" + "tip of: "+rulebase.evaluate(1).get(tip)); } private void plotMFs(String name, T1MF_Interface[] sets, Tuple xAxisRange, int discretizationLevel) { JMathPlotter plotter = new JMathPlotter(17,17,15); for (int i=0;i

private void plotControlSurface(boolean useCentroidDefuzzification, int input1Discs, int input2Discs) { double output; double[] x = new double[input1Discs]; double[] y = new double[input2Discs]; double[][] z = new double[y.length][x.length]; double incrX, incrY; incrX = food.getDomain().getSize()/(input1Discs-1.0); incrY = service.getDomain().getSize()/(input2Discs-1.0);

//first, get the values for(int currentX=0; currentX

 Modify the code so that can input 3 value to predict

Food Quality Membership Functions Service Level Membership Functions Level of Tip Membership Functions Type-1 Fuzzy Logic System Control Surf... * * 9 W1 V Tip 1.0 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0.8.5 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.X .9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0. 0.9.0 3.0 6.0 9.0 12. 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.X Food Quality Service Level 018.021.024.027.030, X MF for unfriendly service MF for ok service MF for friendly service Low tip Medium tip MF for bad food MF for great food High tip Control Surface

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!