Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/lamont/test/derivs2.diderot
ViewVC logotype

View of /branches/lamont/test/derivs2.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2081 - (download) (annotate)
Mon Nov 5 23:26:06 2012 UTC (6 years, 8 months ago) by lamonts
File size: 2282 byte(s)
Creating new developmented branch based on vis12
// derivs2
//
// for debugging transforms of derivatives from index to world, in 2D,
// using synthetic data of a parabola.  The Catmull-Rom can exactly
// reconstruct quadratic functions, so this is a good test case.
//
// Can output image of errors in reconstructed values, or reconstructed
// gradients, according to which of (1), (2), (3) is uncommented below.
// In all cases, output is processed with:
//
// unu reshape -i mip.txt -s 3 300 300 | unu quantize -b 8 -min 0 -max 1 -o derivs2.png
//
// This should produce an *ALL BLACK IMAGE* (modulo a few near-black
// pixels due to numerical precision issues)

// F: full isotropic resolution
image(2)[] Fimg = image ("../data/parab/parab2-150.nrrd");
field#1(2)[] F0 = Fimg ⊛ ctmr;
field#2(2)[] F = Fimg ⊛ bspln3;

// FX: one fifth as many samples along X
image(2)[] FXimg = image ("../data/parab/parab2-x30.nrrd");
field#1(2)[] F0X = FXimg ⊛ ctmr;
field#2(2)[] FX = FXimg ⊛ bspln3;

// FY: one fifth as many samples along Y
image(2)[] FYimg = image ("../data/parab/parab2-y30.nrrd");
field#1(2)[] F0Y = FYimg ⊛ ctmr;
field#2(2)[] FY = FYimg ⊛ bspln3;

int imgSize = 300;
strand sample (int xi, int yi) {
    real xx = lerp(-50.0, 50.0, 0.0, real(xi), real(imgSize-1));
    real yy = lerp(-50.0, 50.0, 0.0, real(yi), real(imgSize-1));
    vec2 p = [xx,yy];
    real f = xx^2 + yy^2;                  // analytic parabola function
    vec2 g = [2.0*xx,2.0*yy];              // analytic gradient
    tensor[2,2] h = [[2.0,0.0],[0.0,2.0]]; // analytic hessian
    output vec3 val = [0.0,0.0,0.0];
    update {

        // Uncomment one of the following:
    
        // (1) These are the errors in the values (this works fine)
        // This works fine; here as a sanity check
        //val = [|F0(p)-f|, |F0X(p)-f|, |F0Y(p)-f|];

        // (2) These are magnitudes of the errors in the gradients
        val = [|∇F(p)-g|, |∇FX(p)-g|, |∇FY(p)-g|];

        // (3) Magnitudes of errors in Hessians
        // The "/50.0" because of greater numerical error in the
        // second derivatives, which may warrant further study
        //val = [|∇(∇F)(p)-h|, |∇(∇FX)(p)-h|, |∇(∇FY)(p)-h|]/50.0;

        stabilize;
    }
}

initially [ sample(xi, yi) | yi in 0..(imgSize-1), xi in 0..(imgSize-1) ];

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0