RE: [math]How to do standardizing (normalizing)
Hi Phil, I have created an issue https://issues.apache.org/jira/browse/MATH-426 and added the code as a svn diff patch to StatUtils. For 'Affected Version' I have noted 'Nightly Builds' which might not be the correct place. Looking forward for the followup! Cheers, Erik van Ingen -Original Message- From: Phil Steitz [mailto:phil.ste...@gmail.com] Sent: 03 October 2010 02:51 To: Commons Users List Subject: Re: [math]How to do standardizing (normalizing) On 10/1/10 8:32 AM, VanIngen, Erik (FIPS) wrote: Hi Luc and others, I have written the standardize function by myself (see below, including the tests). Would it be possible to have this added to Apache Math Commons? Thanks for contributing! We should take discussion of this new feature to the dev list. It would be great if you could open a JIRA ticket and attach a patch including implementation code. We can talk about how to integrate this into [math] in JIRA comments and / or on the dev list. For now, I will just say that the simplest way to add this would be to add a static method called something like normalize to org.apache.commons.math.stat.StatUtils. See http://commons.apache.org/patches.html for info on how to create patches and attach them to JIRA tickets. Do not hesitate to ask either on dev list or in private emails if you need help getting set up. Thanks! Phil /** * The standardise function does not seem to be in Apache math commons. * * * @author Erik van Ingen * */ public class Standardize { /** * Standardise the series, so in the end it is having mean of 0 and a standard deviation of 1. * * * @param series * @return */ public static double[] run(double[] series) { DescriptiveStatistics stats = new DescriptiveStatistics(); // Add the data from the array for (int i = 0; i series.length; i++) { stats.addValue(series[i]); } // Compute mean and standard deviation double currentMean = stats.getMean(); double currentstandardDeviation = stats.getStandardDeviation(); // z = (x- mean)/standardDeviation double[] newSeries = new double[series.length]; for (int i = 0; i series.length; i++) { newSeries[i] = (series[i] - currentMean) / currentstandardDeviation; } return newSeries; } } public class StandardizeTest { /** * Run the test with the values 50 and 100 and assume standardized values with a dinstance of 0.01 */ @Test public void testRun1() { double series[] = { 50, 100 }; double expectedSeries[] = { -0.7, 0.7 }; double[] out = Standardize.run(series); for (int i = 0; i out.length; i++) { assertEquals(out[i], expectedSeries[i], 0.01); } } /** * Run with 77 random values, assuming that the outcome has a mean of 0 and a standard deviation of 1. * * * */ @Test public void testRun2() { int length = 77; double series[] = new double[length]; for (int i = 0; i length; i++) { series[i] = Math.random(); } double standardizedSeries[] = Standardize.run(series); DescriptiveStatistics stats = new DescriptiveStatistics(); // Add the data from the array for (int i = 0; i length; i++) { stats.addValue(standardizedSeries[i]); } double distance = 1E-10; assertEquals(0.0, stats.getMean(), distance); assertEquals(1.0, stats.getStandardDeviation(), distance); } } -Original Message- From: Luc Maisonobe [mailto:luc.maison...@free.fr] Sent: 29 September 2010 18:54 To: Commons Users List Subject: Re: [math]How to do standardizing (normalizing) Le 29/09/2010 12:13, VanIngen, Erik (FIPS) a écrit : Hi Apache Commons Math users I am looking for an easy way of standardizing my values a mean 0 and a standard deviation of 1. What is the best way to do that? I have tried this: DescriptiveStatistics stats = new DescriptiveStatistics(); // adding values // Compute Mean and StandardDeviation double mean = stats.getMean(); double std = stats.getStandardDeviation(); and then standardize each value according z = (x- mean)/std But I would like to have just a function of standardize an array according the parameters mean and std. Is there something like this
Re: jsvc thread monitoring
On 10/05/2010 07:20 PM, Benjamin Watine wrote: Hi I use jsvc to start a deamon on an unix plateform. The service starts and stops as expected, but if my thread crashes, the Deamon don't stops and even restart an other thread. I would like to monitor my thread, and if it crashes, the Deamon stops, exits, and delete PID file. How can I do this ? What do you mean by 'my thread crashes' ? There is a shutdown method that if called with reload==true will cause the jsvc to reload the jvm completely. I need this to allow me to monitor that my service is running well. If your jvm crashes (cores), jsvc will return 1. You can create a shell script that will call jsvc again in that case. Regards -- ^TM - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [validator] Possible to configure multiple error messages for a single validator?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 All, Wow, nothing? :( Usually Niall will at least tell me that nobody cares :) - -chris On 10/1/2010 11:29 AM, Christopher Schultz wrote: All, Any suggestions? I've even considered using a multi-valued msg using a comma as a separator for the two. Something like this: msg=errors.xhtml.syntax, errors.xhtml.no-end-tag Does anyone have any better ideas? Thanks, -chris On 9/29/2010 2:09 PM, Christopher Schultz wrote: All, I've been happily using commons-validator 1.3.1 with Struts 1.3 for some years, now, and I've recently developed my own custom validator that checks for XHTML syntactic validity. Technically, it checks for XHTML validity only when the input looks like this: html/html: everything else validates successfully with no actual XHTML syntax check. Recently, it became clear that users were sometimes forgetting the /html at the end of the input. This caused two problems: first, the input wasn't being validated as XHTML, and second, when the data was then displayed in a web page, it was escaped instead of being rendered as actual HTML. My first instinct was to add a mask validator that checked for an appropriate pattern (that is, html up front with no trailing /html). I implemented that and it works quite well. Then, it occurred to me that I might want some other pattern for some reason for those fields, and that the correct place for that check ought to be in the XHTML validator itself. So I started moving the check described above into my custom validator. Everything was fine until I had to render the error message. Since I'm doing essentially two checks (one for html and matching /html, and a second for actually checking the XHTML syntax), I need two distinct error messages. The configuration for a validator only allows one single msg attribute as shown in my configuration below: validator name=possibleXhtml classname=PossibleXhtmlValidator method=validatePossibleXhtml methodParams=java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionMessages, org.apache.commons.validator.Validator, javax.servlet.http.HttpServletRequest depends= msg=errors.xhtml / I could simply hard-code the error message key into the validator, but that seems less maintainable than I'd like it to be. Is it possible to provide more than one error message key to a validator like this? Other options for me include creating a custom validator that does nothing but check for the html.../html that won't interfere with, say, the mask validator. It still seems to me that my goal ought to be a single validator that is basically self-contained, rather than having two validators that essentially /must/ be used together. Does anyone have any suggestions? Thanks, -chris - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkyrbg0ACgkQ9CaO5/Lv0PD73QCeKJ1yMStcSXf2zmjxZI7Vf2Ju NRwAoL9KqTrjllCW1jJhlLeoohCfxNLg =YBSz -END PGP SIGNATURE- - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [Fileupload] Missing character in the middle of a file
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Brian, On 10/5/2010 12:49 PM, Brian Pontarelli wrote: I haven't tried additional files yet, mostly because it should work for any file in the universe. Of course. I'm not trying to verify that there is a problem (there's clearly a problem somewhere), just trying to get more information about where the problem might be. If it drops bytes at offset 305 only, we should look at the start of the code, but if it drops every 305th byte, maybe we're dealing with an off-by-one error somewhere in a loop. I'll try a few others though to see if it happens the same way with those. Sounds good. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkyrb4MACgkQ9CaO5/Lv0PBWSwCglhWXn9dCK8A6K/EKhF23U3Cn FIUAn2408xfiXfjQ/oc5kj4esRV9HuTW =hGTA -END PGP SIGNATURE- - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [validator] Possible to configure multiple error messages for a single validator?
On Wed, Sep 29, 2010 at 7:09 PM, Christopher Schultz ch...@christopherschultz.net wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 All, I've been happily using commons-validator 1.3.1 with Struts 1.3 for some years, now, and I've recently developed my own custom validator that checks for XHTML syntactic validity. Technically, it checks for XHTML validity only when the input looks like this: html/html: everything else validates successfully with no actual XHTML syntax check. Recently, it became clear that users were sometimes forgetting the /html at the end of the input. This caused two problems: first, the input wasn't being validated as XHTML, and second, when the data was then displayed in a web page, it was escaped instead of being rendered as actual HTML. My first instinct was to add a mask validator that checked for an appropriate pattern (that is, html up front with no trailing /html). I implemented that and it works quite well. Then, it occurred to me that I might want some other pattern for some reason for those fields, and that the correct place for that check ought to be in the XHTML validator itself. So I started moving the check described above into my custom validator. Everything was fine until I had to render the error message. Since I'm doing essentially two checks (one for html and matching /html, and a second for actually checking the XHTML syntax), I need two distinct error messages. The configuration for a validator only allows one single msg attribute as shown in my configuration below: validator name=possibleXhtml classname=PossibleXhtmlValidator method=validatePossibleXhtml methodParams=java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionMessages, org.apache.commons.validator.Validator, javax.servlet.http.HttpServletRequest depends= msg=errors.xhtml / I could simply hard-code the error message key into the validator, but that seems less maintainable than I'd like it to be. Is it possible to provide more than one error message key to a validator like this? Other options for me include creating a custom validator that does nothing but check for the html.../html that won't interfere with, say, the mask validator. It still seems to me that my goal ought to be a single validator that is basically self-contained, rather than having two validators that essentially /must/ be used together. Does anyone have any suggestions? Its been a long time since I worked with Stuts Validator, but take a look at the *standard* validators defined in struts: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/validator/FieldChecks.java?view=markup Its the validation implementation that actually adds the messages to the Struts ActionMessages object - usually by calling Resources.getActionMessage(validator, request, va, field)) http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/validator/Resources.java?view=markup So you need to create your own custom getActionMessage() impl - you could use the msg returned from the field or validator and use that as a prefix and append a different suffix for each error. Alternatively you could define two separate validators - one for each condition. Niall Thanks, - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkyjgOEACgkQ9CaO5/Lv0PBkWwCgjCeACyxBWyv7C4017lfBeMB0 W6AAnioNsVh8uTgjWCPMIHuKIi6AUTLU =7DAj -END PGP SIGNATURE- - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
[net]
Hi Everybody: Hi Everybody: I'm using the FTP API and I need to use a limited bandwidth. The following code works pretty good except for one problem. At the beginning of the transference the program buffers 64KB of data using all the available bandwidth. After that I can control the bandwidth. OutputStream outputStream = new FileOutputStream(localFile); InputStream inputStream = client.retrieveFileStream(remoteFile); byte buf[] = new byte[bufferSize]; int bytesRead = inputStream.read(buf); while (bytesRead != -1) { outputStream.write(buf, 0, bytesRead); Thread.sleep(delay); bytesRead = inputStream.read(buf); } Is it possible to decrease the amount of data that is buffered at the begining? Best Regards, -- Pablo Pinto Computación y Comunicaciones S.A. Almirante Lorenzo Gotuzzo 124, Oficina 1500 Teléfonos : 9135704 - 9135700