Comments (4)
An interesting thought. I'll have to look into it and see if it improves things (or if you can run some tests to check, that would be helpful). I think the Apache HashCodeBuilder it uses unfortunately does isArray checks too.
FWIW though, HashableStateFactory objects are designed to be interchangeable. SimpleHashableStateFactory is just the most simple (heh) and safe catchall approach (and from which the standard abstraction methods provided derive)
However, if performance is an issue, it is wholly encouraged to write your own state-specific HashableStateFactory that is as fast as possible.
Alternatively, if it's your own domain and you'll only need to do one kind of equality for it, you can implement hashcode and equals in the State definition in the most efficient way you can and have the State implement HashableState (with the s() method turning itself), and then use a ReflectiveHashableStateFactory, which will just use the standard implemented methods on the state.
from burlap.
I made various tests with replacing isArray but finally tried out the benchmark I linked to on stackoverflow. Well the result is kind of annoying... it looks like the Java VM already optimized this case.
These are my results of the same benchmark that was linked on stackoverflow:
{s instanceof Object[]} spends 14ms
{s.getClass().isArray()} spends 14ms
{s.getClass().getName().charAt(0) == '['} spends 16ms
That was the same in my tests I did this afternoon. Though in the Profiler, one can see that the isArray() Method uses a lot of time, when I replace it with instanceof Object[](so that the software works as before), the time it needs stays the same, it just is not used within isArray() anymore.
So after all this never was an issue, it just looked like one that fooled both of us - I am sorry for that.
The reason I was digging this deep around is that I am writing several Reflection-Classes for building domains via Annotations so that ObjectInstances, PropositionalMethods, RewardMethods, SampleStates, OOStates and all of that are generated by the Reflection-Classes.
Of course this approach leads to two problems: Performance and what happens if you have special problems that the reflection classes do not cover. Well in the latter one you need to write your own code again or expand the reflection classes until they cover all possibilities. For my special problem I do the latter as it keeps the composition of the classes away so that I can focus on the domain variables, actions and method implementations with having dependency injection that calls my methods with the right objects already casted (and no String[] params variables). It's some kind of simplification.
What I want is that this approach is not much slower than the normal way from the tutorials. And it indeed is possible to be nearly as fast with two ideas: Caching and MethodHandles. So while building the domain via reflecting the classes, I generate MethodHandles that I later can call nearly as fast as native calls. And I cache all that so when the planning runs it uses the already created MethodHandles. Well and while digging with the StateHashing (like I can annotate a field wether it is relevant for the state hash or not, what is the reason why I use the MaskedHashableState) I found that "issue".
So at the moment, I am depending heavily on your provided HashableStateFactories as I am mostly optimizing for usability though still thinking of the performance so that it does not become too slow, which works quite good for now... but it is not finished, just something I am trying for being able to work faster with BURLAP.
from burlap.
I'm not sure if this functionality exists in burlap 3, but I had fairly
good results by using immutable states (copy on write) that also used
immutable objects and attributes. When new states were created by taking
actions, they just modified the attributes and objects that were necessary,
and kept references to everything else. I believe this has been carried
forward into burlap 3.
The advantage of this with regard to hashing, is that you can write a
HashFactory, and associated HashedState that cache the hash values. Then,
only the modified objects and values need to be rehashed. It can
significantly reduce cache times, which has large advantages in state
exploration.
James, does this functionality exist in burlap 3 at the moment?
On Tue, Aug 9, 2016 at 12:20 PM, Adrian [email protected] wrote:
I made various tests with replacing isArray but finally tried out the
benchmark I linked to on stackoverflow. Well the result is kind of
annoying... it looks like the Java VM already optimized this case.These are my results of the same benchmark that was linked on
stackoverflow:
{s instanceof Object[]} spends 14ms
{s.getClass().isArray()} spends 14ms
{s.getClass().getName().charAt(0) == '['} spends 16msThat was the same in my tests I did this afternoon. Though in the
Profiler, one can see that the isArray() Method uses a lot of time, when I
replace it with instanceof Object
http://so%20that%20the%20software%20works%20as%20before, the time it
needs stays the same, it just is not used within isArray() anymore.So after all this never was an issue, it just looked like one that fooled
both of us - I am sorry for that.
The reason I was digging this deep around is that I am writing several
Reflection-Classes for building domains via Annotations so that
ObjectInstances, PropositionalMethods, RewardMethods, SampleStates,
OOStates and all of that are generated by the Reflection-Classes.Of course this approach leads to two problems: Performance and what
happens if you have special problems that the reflection classes do not
cover. Well in the latter one you need to write your own code again or
expand the reflection classes until they cover all possibilities. For my
special problem I do the latter as it keeps the composition of the classes
away so that I can focus on the domain variables, actions and method
implementations with having dependency injection that calls my methods with
the right objects already casted (and no String[] params variables). It's
some kind of simplification.What I want is that this approach is not much slower than the normal way
from the tutorials. And it indeed is possible to be nearly as fast with two
ideas: Caching and MethodHandles
https://docs.oracle.com/javase/8/docs/api/java/lang/invoke/MethodHandles.html.
So while building the domain via reflecting the classes, I generate
MethodHandles that I later can call nearly as fast as native calls. And I
cache all that so when the planning runs it uses the already created
MethodHandles. Well and while digging with the StateHashing (like I can
annotate a field wether it is relevant for the state hash or not, what is
the reason why I use the MaskedHashableState) I found that "issue".So at the moment, I am depending heavily on your provided
HashableStateFactories as I am mostly optimizing for usability though still
thinking of the performance so that it does not become too slow, which
works quite good for now... but it is not finished, just something I am
trying for being able to work faster with BURLAP.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#132 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA_x-jDa9ZnMBV3opeGj4r-oC1K-RR6Qks5qeKi5gaJpZM4Jf_6t
.
from burlap.
Yes, the immutable paradigm more or less does exist in BURLAP 3 because domains now always implement their own State objects and State "copying" can be done shallow or deep. (Also, a lot of the existing domains do use shallow copying).
Given that, it is also absolutely possible to design the state to cache the hash codes so they don't get recomputed and curry them forward with any state "copying."
So yes, for optimizing a domain, that is definitely a viable path.
from burlap.
Related Issues (20)
- Is this a bug in SarsaLam implementation? HOT 2
- DiscretizingMaskedHashableStateFactory is missing methods for handling config HOT 1
- StochasticGames SCPSolver does not work with Java 64-bit under Windows x64 HOT 2
- Renaming objects in a GenericOOState changes the order in objectsByClass list
- is the website source available?
- PerformancePlotter TRIAL_AVERAGES_ONLY Mode
- Null action issue on allApplicableActionsForTypes in ActionUtils.java
- Burlap incompatibilities HOT 1
- ROS - Continous Domain
- Possible bug in "performReachabilityFrom" function in PolicyIteration.java
- Actions are not published after terminal state
- StatePainter's Graphics2D Context Doesn't Update
- getTotalValueIterations() for ValueIteration?
- PolicyUtils.Rollout(Policy, State, SampleModel) will hang when policy does not reach goal state
- Agent can try to move out of bounds, throwing an ArrayIndexOutOfBoundsException HOT 1
- Q Learning Stochastic Movements HOT 5
- PolicyIteration error, type mismatch? HOT 1
- Cumulative probability incorrect in EMinMaxPolicy.getActionDistributionForState() ? HOT 1
- Cumulative probability incorrect in ECorrelatedQJointPolicy.getActionDistributionForState() ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from burlap.