Sponsored Content
Top Forums Programming C language to calculate mean,variance Post 302156752 by cdfd123 on Wednesday 9th of January 2008 01:35:39 AM
Old 01-09-2008
Java

Quote:
Originally Posted by shamrock
So let me see if I understand your post. You need the mean & variance for every line of input and every one of those input lines has ten data values separated by the asterisk character and the first data value is a floating point number like 1.1 2.2 yada yada...correct me if I am wrong.
The code you have posted does not seem to be able to compute the mean and variance of every line of input.
Dear Shamrock,
Yes ,I need the mean and variance for every line of the input and every one of those input lines has ten data values separated by the asterisk character

But
first data value is just 1 2 4 22 211 22 12 22 22 11
and 1. and 2.is just a serial number and can be ignored for that
sorry for that incovenience
if that code not work what can be possible solution? Can u rewrite it?

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

calculate output

I was wondering can anyone give me a clue how to start script which would do the following: I have 2 numbers as input for example: 100 and 1000 and I need to create file and in that file should be written 100 - 199 200 - 299 300 - 399 400 - 499 500 - 599 600 - 699 700 - 799... (3 Replies)
Discussion started by: amon
3 Replies

2. Shell Programming and Scripting

calculating variance in perl programming

#!/usr/bin/perl -w use strict; open(FH,"$ARGV") or die; my @temp=<FH>; close FH; my $mean = Mean(\@temp); my $var = variance(\@temp); print "$var\n"; sub estimate_variance { my ($arrayref) = @_; my ($mean,$result) = (mean($arrayref),0); foreach (@$arrayref) {... (4 Replies)
Discussion started by: cdfd123
4 Replies

3. AIX

calculate time

Hi, How do I calculate time? I need to create an alert if a process is running more than 30 minutes. I need to get the first time and then get another, calculate it if more than 30 mins and then alert it to pager. Can't find it in internet. Thanks in advance, itik (2 Replies)
Discussion started by: itik
2 Replies

4. Shell Programming and Scripting

How To Calculate

I have 2 variables in my shell scripts in which i am using awk and calculating 2 files and getting 2 different variable called in_total and out_total. I want to subtract one variable from another so plz tell me how i can do that. Example is: cat in_file | awk -F: '{ in_total += $1 * 86400... (3 Replies)
Discussion started by: krishna_sicsr
3 Replies

5. Shell Programming and Scripting

Calculate age of a file | calculate time difference

Hello, I'm trying to create a shell script (#!/bin/sh) which should tell me the age of a file in minutes... I have a process, which delivers me all 15 minutes a new file and I want to have a monitoring script, which sends me an email, if the present file is older than 20 minutes. To do... (10 Replies)
Discussion started by: worm
10 Replies

6. Shell Programming and Scripting

Awk total and variance

File1 0358 Not Visible ***:* NA:NA RDF1+TDEV Grp'd (M) RW 102413 0359 Not Visible ***:* NA:NA RDF1+TDEV N/Grp'd (m) RW - 035A Not Visible ***:* NA:NA RDF1+TDEV N/Grp'd (m) RW - 035B Not Visible ***:* NA:NA ... (2 Replies)
Discussion started by: greycells
2 Replies

7. Shell Programming and Scripting

Calculating Running Variance Using Awk

Hi all, I am attempting to calculate a running variance for a file containing a column of numbers. I am using the formula variance=sum((x-mean(x))^2)/(n-1), where x is the value on the current row, and mean(x) is the average of all of the values up until that row. n represents the total number... (1 Reply)
Discussion started by: Jahn
1 Replies

8. Shell Programming and Scripting

AWK sample variance

I would like to calculate 1/n In awk, I wrote the following line for the sigma summation: { summ+=($1-average)^2 } Full code: BEGIN { Print "This script calculate error estimates"; sum=0 } { sum+=$1; n++ } END { average = sum/n } BEGIN { summ=0 } { summ+=($1-average)^2 } END { print... (8 Replies)
Discussion started by: chrisjorg
8 Replies

9. UNIX for Dummies Questions & Answers

Calculate

i have file input abcedef|wert|13|03|10|04|23|A1|13|05|01|09|31 fsdasdf|ferg|12|04|25|21|21|A1|13|02|26|20|31 dfsfsad|gerg|12|04|25|21|21|A1|13|02|25|25|31 i expect the output abcedef|wert|13|03|10|04|23|A1|13|05|01|09|31|9.516666667... (5 Replies)
Discussion started by: radius
5 Replies

10. UNIX for Beginners Questions & Answers

Compare sum of two columns if variance is zero do nothing else send an email

11☺Hi, I have to data sets: One is in .txt format and other is in .csv format, please refer below two outputs from two files. File1.txt SOURCE PAYDATE TOTAL_DOLLARS RECORD_COUNT ASSET 05/25/2018 247643.94 ASSET 06/20/2018 ... (27 Replies)
Discussion started by: Tahir_M
27 Replies
DBD::SQLite::Cookbook(3pm)				User Contributed Perl Documentation				DBD::SQLite::Cookbook(3pm)

NAME
DBD::SQLite::Cookbook - The DBD::SQLite Cookbook DESCRIPTION
This is the DBD::SQLite cookbook. It is intended to provide a place to keep a variety of functions and formals for use in callback APIs in DBD::SQLite. AGGREGATE FUNCTIONS
Variance This is a simple aggregate function which returns a variance. It is adapted from an example implementation in pysqlite. package variance; sub new { bless [], shift; } sub step { my ( $self, $value ) = @_; push @$self, $value; } sub finalize { my $self = $_[0]; my $n = @$self; # Variance is NULL unless there is more than one row return undef unless $n || $n == 1; my $mu = 0; foreach my $v ( @$self ) { $mu += $v; } $mu /= $n; my $sigma = 0; foreach my $v ( @$self ) { $sigma += ($v - $mu)**2; } $sigma = $sigma / ($n - 1); return $sigma; } # NOTE: If you use an older DBI (< 1.608), # use $dbh->func(..., "create_aggregate") instead. $dbh->sqlite_create_aggregate( "variance", 1, 'variance' ); The function can then be used as: SELECT group_name, variance(score) FROM results GROUP BY group_name; Variance (Memory Efficient) A more efficient variance function, optimized for memory usage at the expense of precision: package variance2; sub new { bless {sum => 0, count=>0, hash=> {} }, shift; } sub step { my ( $self, $value ) = @_; my $hash = $self->{hash}; # by truncating and hashing, we can comsume many more data points $value = int($value); # change depending on need for precision # use sprintf for arbitrary fp precision if (exists $hash->{$value}) { $hash->{$value}++; } else { $hash->{$value} = 1; } $self->{sum} += $value; $self->{count}++; } sub finalize { my $self = $_[0]; # Variance is NULL unless there is more than one row return undef unless $self->{count} > 1; # calculate avg my $mu = $self->{sum} / $self->{count}; my $sigma = 0; while (my ($h, $v) = each %{$self->{hash}}) { $sigma += (($h - $mu)**2) * $v; } $sigma = $sigma / ($self->{count} - 1); return $sigma; } The function can then be used as: SELECT group_name, variance2(score) FROM results GROUP BY group_name; Variance (Highly Scalable) A third variable implementation, designed for arbitrarily large data sets: package variance3; sub new { bless {mu=>0, count=>0, S=>0}, shift; } sub step { my ( $self, $value ) = @_; $self->{count}++; my $delta = $value - $self->{mu}; $self->{mu} += $delta/$self->{count}; $self->{S} += $delta*($value - $self->{mu}); } sub finalize { my $self = $_[0]; return $self->{S} / ($self->{count} - 1); } The function can then be used as: SELECT group_name, variance3(score) FROM results GROUP BY group_name; FTS3 fulltext indexing Sparing database disk space As explained in <http://www.sqlite.org/fts3.html#section_6>, each FTS3 table "t" is stored internally within three regular tables "t_content", "t_segments" and "t_segdir". The last two tables contain the fulltext index. The first table "t_content" stores the complete documents being indexed ... but if copies of the same documents are already stored somewhere else, or can be computed from external resources (for example as HTML or MsWord files in the filesystem), then this is quite a waste of space. SQLite itself only needs the "t_content" table for implementing the "offsets()" and "snippet()" functions, which are not always usable anyway (in particular when using utf8 characters greater than 255). So an alternative strategy is to use SQLite only for the fulltext index and metadata, and to keep the full documents outside of SQLite : to do so, after each insert or update in the FTS3 table, do an update in the "t_content" table, setting the content column(s) to NULL. Of course your application will need an algorithm for finding the external resource corresponding to any docid stored within SQLite. Furthermore, SQLite "offsets()" and "snippet()" functions cannot be used, so if such functionality is needed, it has to be directly programmed within the Perl application. In short, this strategy is really a hack, because FTS3 was not originally programmed with that behaviour in mind; however it is workable and has a strong impact on the size of the database file. SUPPORT
Bugs should be reported via the CPAN bug tracker at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBD-SQLite <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBD-SQLite> TO DO
* Add more and varied cookbook recipes, until we have enough to turn them into a separate CPAN distribution. * Create a series of tests scripts that validate the cookbook recipies. AUTHOR
Adam Kennedy <adamk@cpan.org> Laurent Dami <dami@cpan.org> COPYRIGHT
Copyright 2009 - 2012 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.14.2 2012-06-09 DBD::SQLite::Cookbook(3pm)
All times are GMT -4. The time now is 02:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy