Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1f750eb
Thermal updates v1
ebilir Jul 24, 2025
8cfd6a1
cryo-hydro_cond update
ebilir Jul 25, 2025
6458331
try update geoflux
ebilir Jul 30, 2025
8080e91
update hydro conductivity impact of ice
ebilir Aug 10, 2025
d4dd261
LIU changes test
ebilir Mar 25, 2026
bf0ceb7
More LIU updates: revert canopy scaling, correct leaf scaling, add po…
ebilir Mar 25, 2026
5f5aba8
debug print statements
ebilir Mar 26, 2026
bfeba4e
remove Dx code, retain VegK fix
ebilir Mar 26, 2026
2adbc20
VegK and gs update
ebilir Mar 28, 2026
c57ad85
Merge branch 'main' into Eren_HF_DF_28Jun23
ebilir Mar 29, 2026
13910b3
overhaul hydrology implementation for ice correction
ebilir Mar 30, 2026
8049d77
Add new state proximity EDC for constraining thermal gradients
ebilir Mar 30, 2026
1021b63
try w/o ST EDC for E pools
ebilir Mar 31, 2026
be00af2
ST EDC update for bidirectional fluxes
ebilir Apr 2, 2026
519d97b
refactor(LIU_AN_ET): canopy scaling fixes + full documentation
braghiere Apr 3, 2026
832e7b9
merge
ebilir Apr 18, 2026
8b20477
fix merge
ebilir Apr 18, 2026
7c21bd9
add impedance and cryosuction
ebilir Apr 20, 2026
3adb14d
add impedance of infiltration, + correct previous errors
ebilir Apr 20, 2026
184faf7
safety around infiltration impedance
ebilir Apr 20, 2026
21a5eaf
turn ST EDC back on for E pools
ebilir Apr 21, 2026
e32f36e
potxfer, impedance update
ebilir Apr 25, 2026
fb85d0f
remove surface impedance
ebilir Apr 26, 2026
e1d0e96
Merge remote-tracking branch 'origin/main' into Eren_HF_DF_28Jun23
ebilir May 14, 2026
b46a67f
roll back cryosuction (temporary)
ebilir May 14, 2026
dea20f4
again
ebilir May 14, 2026
606f3de
1) update scf_scalar to reconcile SWE,SCF obs; 2) add PEQ for lambda_…
ebilir May 16, 2026
3c5b6fc
timing writeout + alloc opt
ebilir May 25, 2026
0550780
minor cleanup
ebilir May 25, 2026
47f4676
memory opt update
ebilir May 26, 2026
f2f69e2
fixed nolikelihoods-- expected cause of mystery error msg in met only…
ebilir May 26, 2026
b69a9bf
added longitude to CBF summary
ebilir May 28, 2026
ff1d75c
fix state trajectory implementation
ebilir Jun 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions C/mcmc_fun/MHMCMC/MCMC_FUN/ADEMCMC.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ PARS=calloc(PI.npars*NC,sizeof(double));
pars_new=calloc(PI.npars,sizeof(double));
BESTPARS=calloc(PI.npars*NC,sizeof(double));
BESTP=calloc(NC,sizeof(double));
double *npar_de=calloc(PI.npars,sizeof(double));
double *npar1_de=calloc(PI.npars,sizeof(double));
double *npar2_de=calloc(PI.npars,sizeof(double));
double *step_de=calloc(PI.npars,sizeof(double));
double *cpar_ade=calloc(PI.npars,sizeof(double));
double *rpar_ade=calloc(PI.npars,sizeof(double));
double *npar_ade=calloc(PI.npars,sizeof(double));
double *step_ade=calloc(PI.npars,sizeof(double));
double *gamma_ade=calloc(PI.npars,sizeof(double));
/*All accepted parameters*/
/*This is now the last N parameter vectors
* where N is the adaptation frequency*/
Expand Down Expand Up @@ -153,7 +162,8 @@ for ( ;N.ITER<MCO.nOUT;N.ITER++){
//ADEMCMC
double fadapt=(double)N.ITER/((double)MCO.nOUT*MCO.fADAPT);
if (fadapt<1){
withinrange=STEP_ADEMCMC(PARS,pars_new,PI,nn,NC,&gratio);
withinrange=STEP_ADEMCMC(PARS,pars_new,PI,nn,NC,&gratio,cpar_ade,rpar_ade,npar_ade,step_ade,gamma_ade);

}
//Standard DEMCMC
else {
Expand All @@ -162,14 +172,14 @@ for ( ;N.ITER<MCO.nOUT;N.ITER++){
(double)(( (double)random() / (double)RAND_MAX ) < 0.9);
/*take a step (DE-MCMC style)*/
PI.stepsize[0]=PI.stepsize[0];
withinrange=STEP_DEMCMC(PARS,pars_new,PI,nn,NC);
withinrange=STEP_DEMCMC(PARS,pars_new,PI,nn,NC,npar_de, npar1_de, npar2_de, step_de);
gratio=0;
}


lr = log((double)random() / (double)RAND_MAX);
/*p(x) = 0 if parameters outside bounds*/
if (withinrange==1 & -P[nn]+gratio>lr){
if (withinrange==1 && -P[nn]+gratio>lr){
wrlocal=wrlocal+1;
/*Calculate new likelihood*/
P_new=MODEL_LIKELIHOOD(DATA,pars_new);}
Expand Down Expand Up @@ -243,6 +253,15 @@ free(BESTP);
free(PARS);
free(pars_new);
free(P);
free(npar_de);
free(npar1_de);
free(npar2_de);
free(step_de);
free(cpar_ade);
free(rpar_ade);
free(npar_ade);
free(step_ade);
free(gamma_ade);
printf("DEMCMC DONE\n");


Expand Down
26 changes: 23 additions & 3 deletions C/mcmc_fun/MHMCMC/MCMC_FUN/ADEMCMC_301.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ pars_new=calloc(PI.npars,sizeof(double));
BESTPARS=calloc(PI.npars*NC,sizeof(double));
PARS0=calloc(PI.npars*NC,sizeof(double));
BESTP=calloc(NC,sizeof(double));
// Initialize memory for STEP_DEMCMC.c
double *npar_de=calloc(PI.npars,sizeof(double));
double *npar1_de=calloc(PI.npars,sizeof(double));
double *npar2_de=calloc(PI.npars,sizeof(double));
double *step_de=calloc(PI.npars,sizeof(double));
//Intitialize memory for STEP_ADEMCMC.c:
double *cpar_ade=calloc(PI.npars,sizeof(double));
double *rpar_ade=calloc(PI.npars,sizeof(double));
double *npar_ade=calloc(PI.npars,sizeof(double));
double *step_ade=calloc(PI.npars,sizeof(double));
double *gamma_ade=calloc(PI.npars,sizeof(double));
/*All accepted parameters*/
/*This is now the last N parameter vectors
* where N is the adaptation frequency*/
Expand Down Expand Up @@ -153,22 +164,22 @@ for (N.ITER=0;N.ITER<MCO.nOUT;N.ITER++){

//ADEMCMC
if ((double)N.ITER<(double)MCO.nOUT*MCO.fADAPT){
withinrange=STEP_ADEMCMC(PARS0,pars_new,PI,nn,NC,&gratio);
withinrange=STEP_ADEMCMC(PARS0,pars_new,PI,nn,NC,&gratio,cpar_ade,rpar_ade,npar_ade,step_ade,gamma_ade);
}
//Standard DEMCMC
else {
/*Step size is 1 wigth 10% prob iterations*/
PI.stepsize[0]=1 - (1-2.38/sqrt(2*PI.npars)/10)*(double)((double)(random()/(double)RAND_MAX)<0.9);
/*take a step (DE-MCMC style)*/
PI.stepsize[0]=PI.stepsize[0];
withinrange=STEP_DEMCMC(PARS0,pars_new,PI,nn,NC);
withinrange=STEP_DEMCMC(PARS0,pars_new,PI,nn,NC,npar_de, npar1_de, npar2_de, step_de);
gratio=0;
}


lr=log((double)random()/(double)RAND_MAX);
/*p(x) = 0 if parameters outside bounds*/
if (withinrange==1 & -P[nn]+gratio>lr){
if (withinrange==1 && -P[nn]+gratio>lr){
wrlocal=wrlocal+1;
/*Calculate new likelihood*/
P_new=MODEL_LIKELIHOOD(DATA,pars_new);}
Expand Down Expand Up @@ -233,6 +244,15 @@ free(PARS);
free(PARS0);
free(pars_new);
free(P);
free(npar_de);
free(npar1_de);
free(npar2_de);
free(step_de);
free(cpar_ade);
free(rpar_ade);
free(npar_ade);
free(step_ade);
free(gamma_ade);
printf("DEMCMC DONE\n");


Expand Down
23 changes: 20 additions & 3 deletions C/mcmc_fun/MHMCMC/MCMC_FUN/AFDEMCMC.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ if (isinf(P[nn])==-1){
printf("WARNING! P(0)=-inf - MHMCMC may get stuck - if so, please check your initial conditions\n");
}}

// Initialize memory for STEP_AFDEMCMC.c
double *cpar = calloc(PI.npars, sizeof(double));
double *rpar = calloc(PI.npars, sizeof(double));
double *npar = calloc(PI.npars, sizeof(double));
// Initialize memory for STEP_DEMCMC.c
double *npar_de=calloc(PI.npars,sizeof(double));
double *npar1_de=calloc(PI.npars,sizeof(double));
double *npar2_de=calloc(PI.npars,sizeof(double));
double *step_de=calloc(PI.npars,sizeof(double));

/*STEP 2 - BEGIN MCMC*/
for ( ;N.ITER<MCO.nOUT;N.ITER++){
/*Looping through each chain*/
Expand All @@ -153,7 +163,7 @@ for ( ;N.ITER<MCO.nOUT;N.ITER++){
//AFDEMCMC
double fadapt=(double)N.ITER/((double)MCO.nOUT*MCO.fADAPT);
if (fadapt<1){
withinrange=STEP_AFDEMCMC(PARS,pars_new,PI,nn,NC,&gratio);
withinrange=STEP_AFDEMCMC(PARS,pars_new,PI,nn,NC,&gratio, cpar, rpar, npar);
}
//Standard DEMCMC
else {
Expand All @@ -162,14 +172,14 @@ for ( ;N.ITER<MCO.nOUT;N.ITER++){
(double)(( (double)random() / (double)RAND_MAX ) < 0.9);
/*take a step (DE-MCMC style)*/
PI.stepsize[0]=PI.stepsize[0];
withinrange=STEP_DEMCMC(PARS,pars_new,PI,nn,NC);
withinrange=STEP_DEMCMC(PARS,pars_new,PI,nn,NC,npar_de, npar1_de, npar2_de, step_de);
gratio=0;
}


lr = log((double)random() / (double)RAND_MAX);
/*p(x) = 0 if parameters outside bounds*/
if (withinrange==1 & -P[nn]+gratio>lr){
if (withinrange==1 && -P[nn]+gratio>lr){
wrlocal=wrlocal+1;
/*Calculate new likelihood*/
P_new=MODEL_LIKELIHOOD(DATA,pars_new);}
Expand Down Expand Up @@ -243,6 +253,13 @@ free(BESTP);
free(PARS);
free(pars_new);
free(P);
free(cpar);
free(rpar);
free(npar);
free(npar_de);
free(npar1_de);
free(npar2_de);
free(step_de);
printf("DEMCMC DONE\n");


Expand Down
10 changes: 9 additions & 1 deletion C/mcmc_fun/MHMCMC/MCMC_FUN/DEMCMC.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ double *PARS,*pars_new,*BESTPARS;
PARS=calloc(PI.npars*NC,sizeof(double));
pars_new=calloc(PI.npars,sizeof(double));
BESTPARS=calloc(PI.npars*NC,sizeof(double));
double *npar_de=calloc(PI.npars,sizeof(double));
double *npar1_de=calloc(PI.npars,sizeof(double));
double *npar2_de=calloc(PI.npars,sizeof(double));
double *step_de=calloc(PI.npars,sizeof(double));
/*All accepted parameters*/
/*This is now the last N parameter vectors
* where N is the adaptation frequency*/
Expand Down Expand Up @@ -144,7 +148,7 @@ for (N.ITER=0;N.ITER<MCO.nOUT;N.ITER++){
(double)(( (double)random() / (double)RAND_MAX ) < 0.9);
/*take a step (DE-MCMC style)*/
//PI.stepsize[0]=PI.stepsize[0]/10;
withinrange=STEP_DEMCMC(PARS,pars_new,PI,nn,NC);
withinrange=STEP_DEMCMC(PARS,pars_new,PI,nn,NC,npar_de, npar1_de, npar2_de, step_de);
/*p(x) = 0 if parameters outside bounds*/
if (withinrange==1){
wrlocal=wrlocal+1;
Expand Down Expand Up @@ -207,6 +211,10 @@ MCOUT->complete=1;
free(BESTPARS);
free(PARS);
free(P);
free(npar_de);
free(npar1_de);
free(npar2_de);
free(step_de);
printf("DEMCMC DONE\n");


Expand Down
26 changes: 13 additions & 13 deletions C/mcmc_fun/MHMCMC/MCMC_FUN/STEP_ADEMCMC.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <math.h>
#include "../../../math_fun/randn.c"

double STEP_ADEMCMC(double *PARS, double *pars_new, PARAMETER_INFO PI, int C,int NC, double *gratio){
double STEP_ADEMCMC(double *PARS, double *pars_new, PARAMETER_INFO PI, int C,int NC, double *gratio, double *cpar, double *rpar, double *npar, double *step, double *gamma){
/*DE_STEP takes a differential evolution style step*/

/*FIXEDPARS*/
Expand All @@ -15,15 +15,15 @@ double rn;
/*STep 1. Find random sample other than current chain*/

C1=C;
while (C1==C){C1=ceil((double)random()*NC/((double)RAND_MAX))-1;};
while (C1==C){C1=floor((double)random() * NC / ((double)RAND_MAX + 1.0));}

/*Step 2. FInd current chain, reference chain, and step between them*/
/*allocating memory for three normalized parameter vectors*/
double *cpar=calloc(PI.npars,sizeof(double));
double *rpar=calloc(PI.npars,sizeof(double));
double *npar=calloc(PI.npars,sizeof(double));
double *step=calloc(PI.npars,sizeof(double));
double *gamma=calloc(PI.npars,sizeof(double));
// double *cpar=calloc(PI.npars,sizeof(double));
// double *rpar=calloc(PI.npars,sizeof(double));
// double *npar=calloc(PI.npars,sizeof(double));
// double *step=calloc(PI.npars,sizeof(double));
// double *gamma=calloc(PI.npars,sizeof(double));
/*using "*pars" to store sequential outputs*/
for (n=0;n<PI.npars;n++){
cpar[n]=par2nor(PARS[C*PI.npars+n],PI.parmin[n],PI.parmax[n]);
Expand Down Expand Up @@ -74,7 +74,7 @@ int withinlim=1;

for (n=0;n<PI.npars;n++){
npar[n] = rpar[n] + step[n]*gamma[n];
if (npar[n]<0 | npar[n]>1){withinlim=0;}
if (npar[n]<0 || npar[n]>1){withinlim=0;}
}

gratio[0]=0;
Expand Down Expand Up @@ -138,11 +138,11 @@ printf("gn2c = %4.4f\n",gn2c);

}

free(rpar);
free(cpar);
free(npar);
free(step);
free(gamma);
// free(rpar);
// free(cpar);
// free(npar);
// free(step);
// free(gamma);
return withinlim;

}
Expand Down
22 changes: 11 additions & 11 deletions C/mcmc_fun/MHMCMC/MCMC_FUN/STEP_AFDEMCMC.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
#include <stdlib.h>
#include "../../../math_fun/randn.c"

double STEP_AFDEMCMC(double *PARS, double *pars_new, PARAMETER_INFO PI, int C, int NC, double *gratio){
double STEP_AFDEMCMC(double *PARS, double *pars_new, PARAMETER_INFO PI, int C, int NC, double *gratio, double *cpar, double *rpar, double *npar){
/* AFDEMCMC takes an Affine Invariant ensemble step (Goodman & Weare) */

int n, C1=-1;

/* Step 1. Find random sample (reference chain) other than current chain */
C1=C;
while (C1==C){
C1 = ceil((double)random() * NC / ((double)RAND_MAX)) - 1;
C1 = floor((double)random() * NC / ((double)RAND_MAX + 1.0));
}

/* Step 2. Allocate memory for normalized parameter vectors */
/* (Notice we deleted the heavy step and gamma arrays here!) */
double *cpar = calloc(PI.npars, sizeof(double));
double *rpar = calloc(PI.npars, sizeof(double));
double *npar = calloc(PI.npars, sizeof(double));
// /* Step 2. Allocate memory for normalized parameter vectors */
// /* (Notice we deleted the heavy step and gamma arrays here!) */
// double *cpar = calloc(PI.npars, sizeof(double));
// double *rpar = calloc(PI.npars, sizeof(double));
// double *npar = calloc(PI.npars, sizeof(double));

/* Normalize parameters into [0,1] space */
for (n=0; n<PI.npars; n++){
Expand Down Expand Up @@ -68,10 +68,10 @@ double STEP_AFDEMCMC(double *PARS, double *pars_new, PARAMETER_INFO PI, int C, i
gratio[0] = ((double)PI.npars - 1.0) * log(z);
}

/* Step 6. Free memory to prevent leaks */
free(rpar);
free(cpar);
free(npar);
// /* Step 6. Free memory to prevent leaks */
// free(rpar);
// free(cpar);
// free(npar);

return withinlim;
}
26 changes: 13 additions & 13 deletions C/mcmc_fun/MHMCMC/MCMC_FUN/STEP_DEMCMC.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <math.h>
#include "../../../math_fun/randn.c"

int STEP_DEMCMC(double *PARS, double *pars_new, PARAMETER_INFO PI, int C,int NC){
int STEP_DEMCMC(double *PARS, double *pars_new, PARAMETER_INFO PI, int C,int NC, double *npar, double *npar1, double *npar2, double *step){
/*DE_STEP takes a differential evolution style step*/

/*FIXEDPARS*/
Expand All @@ -13,10 +13,10 @@ double rn;


/*allocating memory for three normalized parameter vectors*/
double *npar=calloc(PI.npars,sizeof(double));
double *npar1=calloc(PI.npars,sizeof(double));
double *npar2=calloc(PI.npars,sizeof(double));
double *step=calloc(PI.npars,sizeof(double));
// double *npar=calloc(PI.npars,sizeof(double));
// double *npar1=calloc(PI.npars,sizeof(double));
// double *npar2=calloc(PI.npars,sizeof(double));
// double *step=calloc(PI.npars,sizeof(double));
/*using "*pars" to store sequential outputs*/
for (n=0;n<PI.npars;n++){npar[n]=par2nor(PARS[C*PI.npars+n],PI.parmin[n],PI.parmax[n]);}

Expand All @@ -27,9 +27,9 @@ int withinlim=1;

/*first: pick c1 and c2, make sure that (a) they are between 1 and NC, and (b) they are not C*/
c1=C;c2=C;
while (c1==C | c2==C | c1==c2){
c1=ceil((double)random()*NC/((double)RAND_MAX))-1;
c2=ceil((double)random()*NC/((double)RAND_MAX))-1;}
while (c1==C || c2==C || c1==c2){
c1=floor((double)random() * NC / ((double)RAND_MAX + 1.0));
c2=floor((double)random() * NC / ((double)RAND_MAX + 1.0));}
mstep=0;
/*SAMPLING PARAMETERS*/
for (n=0;n<PI.npars;n++){
Expand All @@ -42,16 +42,16 @@ mstep=0;


npar[n]=npar[n]+step[n];
if (npar[n]<0 | npar[n]>1){withinlim=0;}
if (npar[n]<0 || npar[n]>1){withinlim=0;}

}

for (n=0;n<PI.npars;n++){pars_new[n]=nor2par(npar[n],PI.parmin[n],PI.parmax[n]);}

free(npar);
free(npar1);
free(npar2);
free(step);
// free(npar);
// free(npar1);
// free(npar2);
// free(step);
return withinlim;

}
Expand Down
Loading
Loading