burlap.behavior.singleagent.auxiliary.valuefunctionvis.ValueFunctionVisualizerGUI Java Examples
The following examples show how to use
burlap.behavior.singleagent.auxiliary.valuefunctionvis.ValueFunctionVisualizerGUI.
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: Main.java From cs7641-assignment4 with MIT License | 5 votes |
/** * This method takes care of visualizing the grid, rewards, and specific policy on a nice * BURLAP-predefined GUI. I found this very useful to understand how the algorithm was working. */ private static void visualize(Problem map, ValueFunction valueFunction, Policy policy, State initialState, SADomain domain, HashableStateFactory hashingFactory, String title) { List<State> states = StateReachability.getReachableStates(initialState, domain, hashingFactory); ValueFunctionVisualizerGUI gui = GridWorldDomain.getGridWorldValueFunctionVisualization(states, map.getWidth(), map.getWidth(), valueFunction, policy); gui.setTitle(title); gui.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); gui.initGUI(); }
Example #2
Source File: AnalysisRunner.java From omscs-cs7641-machine-learning-assignment-4 with GNU Lesser General Public License v3.0 | 5 votes |
public void simpleValueFunctionVis(ValueFunction valueFunction, Policy p, State initialState, Domain domain, HashableStateFactory hashingFactory, String title){ List<State> allStates = StateReachability.getReachableStates(initialState, (SADomain)domain, hashingFactory); ValueFunctionVisualizerGUI gui = GridWorldDomain.getGridWorldValueFunctionVisualization( allStates, valueFunction, p); gui.setTitle(title); gui.initGUI(); }
Example #3
Source File: IRLExample.java From burlap_examples with MIT License | 4 votes |
/** * Runs MLIRL on the trajectories stored in the "irlDemo" directory and then visualizes the learned reward function. */ public void runIRL(String pathToEpisodes){ //create reward function features to use LocationFeatures features = new LocationFeatures(this.domain, 5); //create a reward function that is linear with respect to those features and has small random //parameter values to start LinearStateDifferentiableRF rf = new LinearStateDifferentiableRF(features, 5); for(int i = 0; i < rf.numParameters(); i++){ rf.setParameter(i, RandomFactory.getMapped(0).nextDouble()*0.2 - 0.1); } //load our saved demonstrations from disk List<Episode> episodes = Episode.readEpisodes(pathToEpisodes); //use either DifferentiableVI or DifferentiableSparseSampling for planning. The latter enables receding horizon IRL, //but you will probably want to use a fairly large horizon for this kind of reward function. double beta = 10; //DifferentiableVI dplanner = new DifferentiableVI(this.domain, rf, 0.99, beta, new SimpleHashableStateFactory(), 0.01, 100); DifferentiableSparseSampling dplanner = new DifferentiableSparseSampling(this.domain, rf, 0.99, new SimpleHashableStateFactory(), 10, -1, beta); dplanner.toggleDebugPrinting(false); //define the IRL problem MLIRLRequest request = new MLIRLRequest(domain, dplanner, episodes, rf); request.setBoltzmannBeta(beta); //run MLIRL on it MLIRL irl = new MLIRL(request, 0.1, 0.1, 10); irl.performIRL(); //get all states in the domain so we can visualize the learned reward function for them List<State> allStates = StateReachability.getReachableStates(basicState(), this.domain, new SimpleHashableStateFactory()); //get a standard grid world value function visualizer, but give it StateRewardFunctionValue which returns the //reward value received upon reaching each state which will thereby let us render the reward function that is //learned rather than the value function for it. ValueFunctionVisualizerGUI gui = GridWorldDomain.getGridWorldValueFunctionVisualization( allStates, 5, 5, new RewardValueProjection(rf), new GreedyQPolicy((QProvider) request.getPlanner()) ); gui.initGUI(); }
Example #4
Source File: BasicBehavior.java From burlap_examples with MIT License | 4 votes |
public void manualValueFunctionVis(ValueFunction valueFunction, Policy p){ List<State> allStates = StateReachability.getReachableStates(initialState, domain, hashingFactory); //define color function LandmarkColorBlendInterpolation rb = new LandmarkColorBlendInterpolation(); rb.addNextLandMark(0., Color.RED); rb.addNextLandMark(1., Color.BLUE); //define a 2D painter of state values, specifying which attributes correspond to the x and y coordinates of the canvas StateValuePainter2D svp = new StateValuePainter2D(rb); svp.setXYKeys("agent:x", "agent:y", new VariableDomain(0, 11), new VariableDomain(0, 11), 1, 1); //create our ValueFunctionVisualizer that paints for all states //using the ValueFunction source and the state value painter we defined ValueFunctionVisualizerGUI gui = new ValueFunctionVisualizerGUI(allStates, svp, valueFunction); //define a policy painter that uses arrow glyphs for each of the grid world actions PolicyGlyphPainter2D spp = new PolicyGlyphPainter2D(); spp.setXYKeys("agent:x", "agent:y", new VariableDomain(0, 11), new VariableDomain(0, 11), 1, 1); spp.setActionNameGlyphPainter(GridWorldDomain.ACTION_NORTH, new ArrowActionGlyph(0)); spp.setActionNameGlyphPainter(GridWorldDomain.ACTION_SOUTH, new ArrowActionGlyph(1)); spp.setActionNameGlyphPainter(GridWorldDomain.ACTION_EAST, new ArrowActionGlyph(2)); spp.setActionNameGlyphPainter(GridWorldDomain.ACTION_WEST, new ArrowActionGlyph(3)); spp.setRenderStyle(PolicyGlyphPainter2D.PolicyGlyphRenderStyle.DISTSCALED); //add our policy renderer to it gui.setSpp(spp); gui.setPolicy(p); //set the background color for places where states are not rendered to grey gui.setBgColor(Color.GRAY); //start it gui.initGUI(); }
Example #5
Source File: BasicBehavior.java From burlap_examples with MIT License | 3 votes |
public void simpleValueFunctionVis(ValueFunction valueFunction, Policy p){ List<State> allStates = StateReachability.getReachableStates(initialState, domain, hashingFactory); ValueFunctionVisualizerGUI gui = GridWorldDomain.getGridWorldValueFunctionVisualization(allStates, 11, 11, valueFunction, p); gui.initGUI(); }
Example #6
Source File: GridWorldDomain.java From burlap with Apache License 2.0 | 2 votes |
/** * Creates and returns a {@link burlap.behavior.singleagent.auxiliary.valuefunctionvis.ValueFunctionVisualizerGUI} * object for a grid world. The value of states * will be represented by colored cells from red (lowest value) to blue (highest value). North-south-east-west * actions will be rendered with arrows using {@link burlap.behavior.singleagent.auxiliary.valuefunctionvis.common.ArrowActionGlyph} * objects. The GUI will not be launched by default; call the * {@link burlap.behavior.singleagent.auxiliary.valuefunctionvis.ValueFunctionVisualizerGUI#initGUI()} * on the returned object to start it. * @param states the states whose value should be rendered. * @param maxX the maximum value in the x dimension * @param maxY the maximum value in the y dimension * @param valueFunction the value Function that can return the state values. * @param p the policy to render * @return a gridworld-based {@link burlap.behavior.singleagent.auxiliary.valuefunctionvis.ValueFunctionVisualizerGUI} object. */ public static ValueFunctionVisualizerGUI getGridWorldValueFunctionVisualization(List <State> states, int maxX, int maxY, ValueFunction valueFunction, Policy p){ return ValueFunctionVisualizerGUI.createGridWorldBasedValueFunctionVisualizerGUI(states, valueFunction, p, new OOVariableKey(CLASS_AGENT, VAR_X), new OOVariableKey(CLASS_AGENT, VAR_Y), new VariableDomain(0, maxX), new VariableDomain(0, maxY), 1, 1, ACTION_NORTH, ACTION_SOUTH, ACTION_EAST, ACTION_WEST); }