training Hopefield network with encog in java - java

I started working with this network. And I wrote some code, but I am not sure whether I am doing it right or not. here is what I do:
First create the network HopefieldNetwork net = new HopefieldNetwork(50).
Than add all patterns, with net.addPattern(aPattern) where aPattern is of type BasicMLData and changes in a loop to add all patterns.
Now do net.runUntilStable(5000) for training with 5000 iterations max. Is this right?
Now we have the trained network. Get output like out = (BasicMLData) net.compute(input)
So is everything OK?

I found the solution.
You have to call setCurrentState then runUntilStable then getCurrentState to get output.

Related

SourceAFIS Java - Create fingerprint template it's too slow

I am using SourcesAFIS Fingerprint in an Android Java application to compare users' fingerprints and have the following problem: My application is taking too long to convert the user's fingerprint bytes into FingerprintTemplate, even sometimes the application is closed. To my misfortune I need to create this FingerprintTemplate object inside a loop in order to get the biometrics that are returned from the database, which ends up slowing down even more.
Code snippet
//Returns database biometries and assigns list
listBiometria = conSql.selecionarBiometria();
FingerprintTemplate candidate = new FingerprintTemplate();
candidate.dpi(500);
candidate.create(img);
for(Biometry biometry : listBiometria)
{
FingerprintTemplate probe = new FingerprintTemplate()
.dpi(500)
.create(biometry.getBiometria());
score = new FingerprintMatcher()
.index(probe)
.match(candidate);
}
Well if in case anyone has a problem similar to this, I found the github of the creator of SourcesAFIS and asked this question there and received the following answer:Android feature extractor performance is indeed poor. Improvements are possible. Meantime it is recommended to use a recent device with solid floating-point performance.
In any case, you shouldn't be looping over images like that. Perform feature extraction after image acquisition and subsequently cache the template like the tutorial says.
Link: https://github.com/robertvazan/sourceafis-net/issues/2

Get all statemachines with their name and ARN

I want to create some metrics around step functions that we currently have. I was able to make that list using python but for some reason, we are limited to use java in our company.
I want to
List ALL statemachines which are defined in current region for given account. in python i was able to achieve this using
stepFunction = boto3.client('stepfunctions', region_name='eu-west-1')
stepFunction.list_state_machines()
Then from that, i want to list all Tasks for that given statemachine and get some metrics.
In Java, I am unable to find an API reference which will give me ALL statemachines. I was looking at http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/index.html?com/amazonaws/services/stepfunctions/model/ListStateMachinesRequest.html API but no help.
To get the activity tasks for every state machine in your library, you will need to use the describeStateMachine call. Follow this pattern (please excuse the pseudocode):
state_machines = list_state_machines()
for each (state machine arn : state_machines)
sm = describe_statemachine(state_machine_arn)
/*parse through the definition here and use regex pattern on the arns*/
activityarns = sm.getDefinition().find(/regex/)
metrics.add(sm.arn, activityarns)
endforeach
Hope this helps!

Limit Android Google Places API to search only given area

I`m using Android Google Places API to autocomplete streets and addresses. The problem is that it gives all streets from a whole country. Of course I added bounds to limit place for search, but it doesnt work correctly - it gives only priority, so in other words best results will be higher in list, nothing more
So code:
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
.setTypeFilter(AutocompleteFilter.TYPE_FILTER_ADDRESS)
.setCountry("RU")
.build();
Intent intent =
new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
.zzih(searchString) //that is for passing search string from toolbar
.setFilter(typeFilter)
.setBoundsBias(city.getBounds())
.build(this);
In short the problem is:
When I type in search something like "Lenina Street" I see a lot of useless results out of bounds set in .setBoundsBias(city.getBounds()). Just imagine that something like "Lenina Street" exists in almost every locality!
How can I fix the problem and limit search results?
P.S.
I know I can use Google Places Web API or by GeoDataApi.getAutocompletePredictions() and filter results manually,
but that means I have to write UI manually too, what I dont want to
do.
Thats even worse than I thought. Even if I get results from Web API or through GeoDataApi I have only predictions which doesnt contain coordinates, only placeId. So if I want to filter predictions by coordinates I have to do request for each placeId. In other words if I got 20 places I will have to do 20 more requests to find out coordinates.
Also I can add city name in searchString, that makes results better (but not at all) but it makes writing of address unclear and city name takes place, so its not good solution too.
I'm afraid Places API for Android doesn't support strict bounds yet. There is a feature request in Google Issue tracker to implement this:
https://issuetracker.google.com/issues/38188994
Feel free to star this feature request to add your vote and subscribe to notifications from Google.
In the meantime the workaround might be using Places API web service that supports strict bounds and implement the UI manually.
UPDATE
The feature request was marked as Fixed by Google. Have a look at https://stackoverflow.com/a/50134855/5140781 that shows how to apply strict bounds in Places API for Android.

Interpreting iOS code to get Bluetooth Low Energy data on Android

I was sent iOS C code to get data from a Bluetooth Low Energy scale and I need to find out how to create similar functions into Android Java code.
The scale I am working with aren't using typical UUIDs and formatting.
I already have a scanner set up with the ability to write and listen to notifications.
What I need to do is figure out how to get the weight data.
I know is that 0XFFF0 is the service UUID, 0XFFF1 is the write characteristic and 0XFFF4 is the notify characteristic.
I'm guessing it writes something, then the scale gives you the data. But I'm not sure what.
Plus I think the scale sends the data with NSUTF8StringEncoding if I'm reading it correctly. How would I implement this on Java?
Here is the code sent to me:
http://www.anj.fyi/BTManagerlib.m (I tried to post the code here, but it's registering as spam for some odd reason)
I really appreciate the help guys.
Many thanks.
"The scale I am working with aren't using typical UUIDs and formatting."
Yes, it uses, except it is written in 16-bit format If you want 128-bit UUID use XXXXYYYY-0000-1000-8000-00805F9B34FB base to create it.
From the example that you have posted:
-(void)writeDataToBlue:(NSNotification *)note
{
id obj = [note object];
_senddata = obj;
[self sendBlueToothData:_senddata showAlert:YES];
}
it is clear that data to be written to the device are not bundled into the source code, but they are received via notification center, from some other class. Ask them for device documentation or full source code, otherwise you won't be able to make any conclusions.

URL.openStream() is very slow when ran on school's unix server

I am using URL.openStream() to download many html pages for a crawler that I am writing. The method runs great locally on my mac however on my schools unix server the method is extremely slow. But only when downloading the first page.
Here is the method that downloads the page:
public static String download(URL url) throws IOException {
Long start = System.currentTimeMillis();
InputStream is = url.openStream();
System.out.println("\t\tCreated 'is' in "+((System.currentTimeMillis()-start)/(1000.0*60))+"minutes");
...
}
And the main method that invokes it:
LinkedList<URL> ll = new LinkedList<URL>();
ll.add(new URL("http://sheldonbrown.org/bicycle.html"));
ll.add(new URL("http://www.trentobike.org/nongeo/index.html"));
ll.add(new URL("http://www.trentobike.org/byauthor/index.html"));
ll.add(new URL("http://www.myra-simon.com/bike/travel/index.html"));
for (URL tmp : ll) {
System.out.println();
System.out.println(tmp);
CrawlerTools.download(tmp);
}
Output locally (Note: all are fast):
http://sheldonbrown.org/bicycle.html
Created 'is' in 0.00475minutes
http://www.trentobike.org/nongeo/index.html
Created 'is' in 0.005083333333333333minutes
http://www.trentobike.org/byauthor/index.html
Created 'is' in 0.0023833333333333332minutes
http://www.myra-simon.com/bike/travel/index.html
Created 'is' in 0.00405minutes
Output on School Machine Server (Note: All are fast except the first one. The first one is slow regardless of what the first site is):
http://sheldonbrown.org/bicycle.html
Created 'is' in 3.2330666666666668minutes
http://www.trentobike.org/nongeo/index.html
Created 'is' in 0.016416666666666666minutes
http://www.trentobike.org/byauthor/index.html
Created 'is' in 0.0022166666666666667minutes
http://www.myra-simon.com/bike/travel/index.html
Created 'is' in 0.009533333333333333minutes
I am not sure if this is a Java issue (*A problem in my Java code) or a server issue. What are my options?
When run on the server this is the output of the time command:
real 3m11.385s
user 0m0.277s
sys 0m0.113s
I am not sure if this is relevant... What should I do to try and isolate my problem..?
You've answered your own question. It's not a Java issue, it has to do with your school's network or server.
I'd recommend that you report your timings in milliseconds and see if they're repeatable. Run that test in a loop - 1,000 or 10,000 times - and keep track of all the values you get. Import them into a spreadsheet and calculate some statistics. Look at the distribution of values. You don't know if the one data point that you have is an outlier or the mean value. I'd recommend that you do this for both networks in exactly the same way.
I'd also recommend using Fiddler or some other tool to watch network traffic as you download. You can get better insight into what's going on and perhaps ferret out the root cause.
But it's not Java. It's your code, your network. If this was a bug in the JDK it would have been fixed a long time ago. Suspect yourself first, last, and always.
UPDATE:
My network admin assured me that this
was a bad java implementation Not a
network problem. What do you think?
"Assured" you? What evidence did s/he produce to support this conclusion? What data? What measurements were taken? Sounds like laziness and ignorance to me.
It certainly doesn't explain why all the other requests behave just fine. What changed in Java between the first and subsequent calls? Did the JVM suddenly rewrite itself?
You can accept it if you want, but I'd say shame on your network admin for not being more curious. It would have been more honorable to be honest and say they didn't know, didn't have time, and weren't interested.
By Default Java prefers to use IPv6. My school's firewall
drops all IPv6 traffic (with no warning). After 3 minutes, 15 seconds Java falls back to IPv4. Seems strange to me that it takes so long to fall back to IPv4.
duffymo's answer, essentially: "Go talk to your network admin", helped me to solve the problem however I think that this is a problem caused by a strange Java implementation and a strange network configuration.
My network admin assured me that this was a bad java implementation Not a network problem. What do you think?

Categories

Resources