-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes made to make mogi and cdm run properly #11
base: master
Are you sure you want to change the base?
Changes from all commits
4a29dfc
cc66c00
7dc60a1
c108ede
a4bb6cc
d86d3cb
d42abb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,10 +49,8 @@ def initialize(self, model, **kwds): | |
libcdm.oid(source, oid) | ||
# inform the source about the parameter layout; assumes contiguous parameter sets | ||
libcdm.layout(source, | ||
model.xIdx, model.dIdx, | ||
model.openingIdx, model.aXIdx, model.omegaXIdx, | ||
model.xIdx, model.dIdx, model.openingIdx, model.aXIdx, model.omegaXIdx, | ||
model.offsetIdx) | ||
|
||
# nothing to do | ||
return self | ||
|
||
|
@@ -90,7 +88,8 @@ def dataLikelihood(self, model, step): | |
# get the residuals | ||
residuals = predicted.getRow(sample) | ||
# compute the norm, and normalize it | ||
llk = normalization - norm.eval(v=residuals, sigma_inv=cd_inv) / 2 | ||
normeval = norm.eval(v=residuals, sigma_inv=cd_inv) | ||
llk = normalization - normeval**2.0 / 2.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corrected the calculation of LLK. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch! |
||
# store it | ||
dataLLK[sample] = llk | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,20 +50,20 @@ def dataLikelihood(self, model, step): | |
samples = θ.rows | ||
# get the parameter sets | ||
psets = model.psets | ||
|
||
# get the offsets of the various parameter sets | ||
xIdx = model.xIdx | ||
yIdx = model.yIdx | ||
dIdx = model.dIdx | ||
openingIdx = model.openingIdx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing significant. Just reordered the variable for consistency. |
||
aXIdx = model.aXIdx | ||
aYIdx = model.aYIdx | ||
aZIdx = model.aZIdx | ||
omegaXIdx = model.omegaXIdx | ||
omegaYIdx = model.omegaYIdx | ||
omegaZIdx = model.omegaZIdx | ||
openingIdx = model.openingIdx | ||
offsetIdx = model.offsetIdx | ||
|
||
# get the observations | ||
los = model.los | ||
oid = model.oid | ||
|
@@ -91,9 +91,10 @@ def dataLikelihood(self, model, step): | |
omegaZ = parameters[omegaZIdx] | ||
|
||
# make a source using the sample parameters | ||
cdm = source(x=x, y=y, d=d, | ||
cdm = source(x=x, y=y, d=d, opening=opening, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modified function variable referencing/order for consistency. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with python pass-by-name, the order of arguments is not important |
||
ax=aX, ay=aY, az=aZ, omegaX=omegaX, omegaY=omegaY, omegaZ=omegaZ, | ||
opening=opening, v=model.nu) | ||
v=model.nu) | ||
|
||
# compute the expected displacement | ||
u = cdm.displacements(locations=locations, los=los) | ||
|
||
|
@@ -103,11 +104,11 @@ def dataLikelihood(self, model, step): | |
for obs in range(observations): | ||
# appropriate for the corresponding dataset | ||
u[obs] -= parameters[offsetIdx + oid[obs]] | ||
|
||
# compute the norm of the displacements | ||
residual = norm.eval(v=u, sigma_inv=cd_inv) | ||
normeval = norm.eval(v=u, sigma_inv=cd_inv) | ||
# normalize and store it as the data log likelihood | ||
dataLLK[sample] = normalization - residual/2 | ||
dataLLK[sample] = normalization - normeval**2.0 /2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corrected the calculation of the LLK. |
||
|
||
# all done | ||
return self | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,9 +78,9 @@ def displacements(self, locations, los): | |
# allocate space for the result | ||
u = altar.vector(shape=len(locations)) | ||
# compute the displacements | ||
ue, un, uv = CDM(Xf, Yf, x_src, y_src, d_src, | ||
omegaX_src, omegaY_src, omegaZ_src, ax_src, ay_src, az_src, | ||
opening, v) | ||
ue, un, uv = CDM(Xf, Yf, x_src, y_src, d_src, opening, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines 81-83: Modified function variable referencing/order for consistency. |
||
ax_src, ay_src, az_src, omegaX_src, omegaY_src, omegaZ_src, | ||
v) | ||
# go through each observation location | ||
for idx, (ux,uy,uz) in enumerate(zip(ue, un, uv)): | ||
# project the expected displacement along LOS and store | ||
|
@@ -91,8 +91,8 @@ def displacements(self, locations, los): | |
|
||
|
||
# meta-methods | ||
def __init__(self, x=x, y=y, d=d, omegaX=omegaX, omegaY=omegaY, omegaZ=omegaZ, | ||
ax=ax, ay=ay, az=az, opening=opening, v=v, **kwds): | ||
def __init__(self, x=x, y=y, d=d, opening=opening, ax=ax, ay=ay, az=az, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines 95-96: Same here--modified function variable referencing/order for consistency. |
||
omegaX=omegaX, omegaY=omegaY, omegaZ=omegaZ, v=v, **kwds): | ||
# chain up | ||
super().__init__(**kwds) | ||
# store the location | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ def norm(v): | |
return numpy.sqrt(v.dot(v)) | ||
|
||
|
||
def CDM(X, Y, X0, Y0, depth, omegaX, omegaY, omegaZ, ax, ay, az, opening, nu): | ||
def CDM(X, Y, X0, Y0, depth, opening, ax, ay, az, omegaX, omegaY, omegaZ, nu): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here--modified function variable referencing/order for consistency. |
||
""" | ||
CDM | ||
calculates the surface displacements and potency associated with a CDM | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ | |
# my model | ||
import altar.models.cdm | ||
|
||
|
||
# app | ||
class CDM(altar.application, family="altar.applications.cdm"): | ||
""" | ||
|
@@ -46,13 +45,13 @@ class CDM(altar.application, family="altar.applications.cdm"): | |
omegaX = altar.properties.float(default=0) | ||
omegaX.doc = "the CDM rotation about the x axis" | ||
|
||
omegaY = altar.properties.float(default=0) | ||
omegaY = altar.properties.float(default=-45) | ||
omegaY.doc = "the CDM rotation about the y axis" | ||
|
||
omegaZ = altar.properties.float(default=0) | ||
omegaZ.doc = "the CDM rotation about the z axis" | ||
|
||
opening = altar.properties.float(default=1e-3) | ||
opening = altar.properties.float(default=100.0) | ||
opening.doc = "the tensile component of the Burgers vector of the dislocation" | ||
|
||
nu = altar.properties.float(default=.25) | ||
|
@@ -97,16 +96,16 @@ def cdm(self): | |
observations = len(stations) | ||
# make a source | ||
source = altar.models.cdm.source( | ||
x=self.x, y=self.y, d=self.d, | ||
x=self.x, y=self.y, d=self.d, opening=self.opening, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines 99-102: Modified function variable referencing/order for consistency. |
||
ax=self.aX, ay=self.aY, az=self.aZ, | ||
omegaX=self.omegaX, omegaY=self.omegaY, omegaZ=self.omegaZ, | ||
opening=self.opening, v=self.nu) | ||
v=self.nu) | ||
|
||
# observe all displacements from the same angle for now | ||
theta = π/4 # the azimuthal angle | ||
phi = π # the polar angle | ||
# build the common projection vector | ||
s = sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta) | ||
s = -sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta) | ||
|
||
# allocate a matrix to hold the projections | ||
los = altar.matrix(shape=(observations,3)) | ||
|
@@ -131,14 +130,7 @@ def cdm(self): | |
for idx, (x,y) in enumerate(stations): | ||
# make a new entry in the data sheet | ||
observation = data.pyre_new() | ||
# western stations | ||
if x < 0: | ||
# come from a different data set | ||
observation.oid = 1 | ||
# than | ||
else: | ||
# eastern stations | ||
observation.oid = 0 | ||
observation.oid = 0 | ||
|
||
# record the location of this observation | ||
observation.x = x | ||
|
@@ -158,7 +150,7 @@ def cdm(self): | |
# go through the observations | ||
for idx, observation in enumerate(data): | ||
# set the covariance to a fraction of the "observed" displacement | ||
correlation[idx,idx] = 1.0 #.01 * observation.d | ||
correlation[idx,idx] = 0.0001 #1.0 #.01 * observation.d | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1.0 m is quite large for an observation error (variance). |
||
|
||
# all done | ||
return data, correlation | ||
|
@@ -169,11 +161,16 @@ def makeStations(self): | |
Create a set of station coordinate | ||
""" | ||
# get some help | ||
import itertools | ||
# build a set of points on a grid | ||
stations = itertools.product(range(-5,6), range(-5,6)) | ||
import numpy as np | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 171-177: I think for the synthetic case, this is better to constrain the number of points. |
||
xx = np.linspace(-6000,6000, 15) | ||
yy = np.linspace(-6000,6000, 15) | ||
x,y = np.meshgrid(xx, yy) | ||
x=x.flatten() | ||
y = y.flatten() | ||
stations = [tuple((y[i], x[i])) for i in range(0,len(x))] | ||
|
||
# and return it | ||
return tuple((x*1000, y*1000) for x,y in stations) | ||
return stations | ||
|
||
|
||
# bootstrap | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,16 +90,14 @@ displacements(gsl_matrix_view * samples, gsl_matrix * predicted) const { | |
auto omegaY = gsl_matrix_get(&samples->matrix, sample, _omegaYIdx); | ||
auto omegaZ = gsl_matrix_get(&samples->matrix, sample, _omegaZIdx); | ||
|
||
|
||
// compute the displacements | ||
cdm(_locations, | ||
xSrc, ySrc, dSrc, | ||
openingSrc, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modified function variable referencing/order for consistency. |
||
aX, aY, aZ, | ||
omegaX, omegaY, omegaZ, | ||
openingSrc, | ||
_nu, | ||
disp); | ||
|
||
// apply the location specific projection to LOS vector and dataset shift | ||
for (auto loc=0; loc<_locations->size1; ++loc) { | ||
// compute the components of the unit LOS vector | ||
|
@@ -109,16 +107,16 @@ displacements(gsl_matrix_view * samples, gsl_matrix * predicted) const { | |
|
||
// get the three components of the predicted displacement for this location | ||
auto ux = gsl_matrix_get(disp, loc, 0); | ||
auto uy = gsl_matrix_get(disp, loc, 0); | ||
auto ud = gsl_matrix_get(disp, loc, 0); | ||
auto uy = gsl_matrix_get(disp, loc, 1); | ||
auto ud = gsl_matrix_get(disp, loc, 2); | ||
|
||
// project; don't forget {ud} is positive into the ground | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a depth value. It is the vertical component. |
||
auto u = ux*nx + uy*ny - ud*nz; | ||
// project | ||
auto u = ux*nx + uy*ny + ud*nz; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a depth value and should be '+' sign. |
||
// find the shift that corresponds to this observation | ||
auto shift = gsl_matrix_get(&samples->matrix, sample, _offsetIdx+_oids[loc]); | ||
// and apply it to the projected displacement | ||
u -= shift; | ||
|
||
// save | ||
gsl_matrix_set(predicted, sample, loc, u); | ||
} | ||
|
@@ -147,7 +145,6 @@ residuals(gsl_matrix * predicted) const { | |
// unpack the number of samples and number of observations | ||
auto nSamples = predicted->size1; | ||
auto nObservations = predicted->size2; | ||
|
||
// go through all observations | ||
for (auto obs=0; obs < nObservations; ++obs) { | ||
// get the corresponding measurement | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified function variable referencing/order for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks like merging two lines into one; am i missing something