Specifying new priors¶
You can specify new priors by subclassing blendz.model.ModelBase, redefining
the four functions that return the priors and instantiating your new model for blendz.photoz.
Creating a new model class¶
Your new class should have the following basic layout:
from blendz.model import ModelBase
class MyNewModel(ModelBase):
#Optional:
def __init__(self, new_prior_params, **kwargs):
#Run the setup defined in ModelBase
super(MyNewModel, self).__init__(**kwargs)
#Do some other setup with your new_prior_parameters
#Mandatory:
def lnPrior(self, redshift, magnitude):
#Definition of P(z_a, t_a, m_0a) for all t_a
return 0.
#Optional:
def correlationFunction(self, redshifts):
#Definition of xi({z})
return 0.
#Optional:
def calibrate(self, photometry, cached_likelihood, **kwargs):
return 0.
A few things to note:
- The
__init__function is optional but allows you to define additional setup tasks that are done when your model is instantiated. It is important you call the superclass__init__if you define this. - The
correlationFunctionfunction is also optional. The functionself.comovingSeparation(z_lo, z_hi)defined inModelBasemay be helpful. - While
__init__is optional, you must redefinelnPrior. This function takes afloatfor both the redshift and magnitude, and returns anumpy.arrayof the natural log of the prior for each template type (not each template). Theself.possible_typesattribute is a list of the possible types, where each element is a string with the name of that type. These are automatically read from the template set file supplied at runtime. - The
**kwargsget passed byModelBasetoConfiguration, allowing you to edit the configuration like otherblendzclasses using keyword arguments. - The
redshift,magnitudeandcomponent_ref_magarguments passed to natural-log prior functions are floats, while theredshiftsargument incorrelationFunctionis a 1Dnumpyarray. - The
calibratefunction is also optional. This takes as arguments ablendz.photometry.Photometryobject and anumpy.arrayof shape(num_galaxies, num_templates)filled with the likelihood. This function is called by theblendz.Photoz.calibrate(**kwargs)function, with any keyword arguments passed to the function here. There is no return value for this function; the default model writes the resulting parameters to a configuration file that can be read byblendz.Photoz.
Using the new model¶
The new model can simply be instantiated and passed to blendz.Photoz as a keyword argument.
new_model = MyNewModel(new_prior_params=42, template_set='BPZ6')
pz = blendz.Photoz(model=new_model)