Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Calculate jackknife error from of each column of a multi-column file

by Marshall (Canon)
on Dec 16, 2020 at 01:58 UTC ( [id://11125270]=note: print w/replies, xml ) Need Help??


in reply to Calculate jackknife error from of each column of a multi-column file

I am very confused as to what this thing is supposed to do!
I ran just the first part of the code and this is what I get.
The n array is not multi-dimensional. There is not data in that array anyway in this first loop. $x[$n[$j]][$j] doesn't make sense to me.
Update: I guess $x[$n[$j]//=0][$j] = $column[$j]; "works", but I still don't quite get it.
#! /usr/bin/perl use warnings; use strict; use Data::Dumper; my @n=0; my @x; my $j; my $i; my $dg; my @x_jack; my @x_tot=0; my $cols; my $col_start=0; # read in the data while(<DATA>) { my @column = split(); $cols=@column; foreach my $j ($col_start .. $#column) { $x[$n[$j]][$j] = $column[$j]; $x_tot[$j] += $x[$n[$j]][$j]; $n[$j]++; } } print "\n"; print "THE X ARRAY IS\n"; foreach my $rowref (@x) { print "@$rowref\n"; } print "\n"; print "THE N ARRAY IS:\n"; print "@n"; =PRINTS: Use of uninitialized value within @n in array element at line 22, <DAT +A> line 1. Use of uninitialized value within @n in array element at line 23, <DAT +A> line 1. Use of uninitialized value within @n in array element at line 22, <DAT +A> line 1. Use of uninitialized value within @n in array element at line 23, <DAT +A> line 1. Use of uninitialized value within @n in array element at line 22, <DAT +A> line 1. Use of uninitialized value within @n in array element at line 23, <DAT +A> line 1. THE X ARRAY IS 1.1 2.1 3.1 4.1 1.2 2.2 3.2 4.2 1.3 2.3 3.3 4.3 1.4 2.4 3.4 4.4 THE N ARRAY IS: 4 4 4 4 =cut __DATA__ 1.1 2.1 3.1 4.1 1.2 2.2 3.2 4.2 1.3 2.3 3.3 4.3 1.4 2.4 3.4 4.4

Replies are listed 'Best First'.
Re^2: Calculate jackknife error from of each column of a multi-column file
by GrandFather (Saint) on Dec 16, 2020 at 02:21 UTC

    Let's do $x[$n[$j]][$j] in bits:

    foreach my $j ($col_start .. $#column) { my $nIndex = $n[$j]; $x[$nIndex][$j] = $column[$j]; $x_tot[$j] += $x[$nIndex][$j]; $n[$j]++; }

    The 'uninitialized value' error can then be fix by:

    foreach my $j ($col_start .. $#column) { my $nIndex = $n[$j] // 0; $x[$nIndex][$j] = $column[$j]; $x_tot[$j] += $x[$nIndex][$j]; $n[$j]++; }
    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
      Yes, I see now that $x[$n[$j]//=0][$j] = $column[$j]; is the answer. Thanks! The nested brackets confused my brain. I highly suspect that there is a more simple formulation of this part of the algorithm. For example, transforming a square matrix is not that hard and then you go row by row to get the column sums.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11125270]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-24 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found