text:
# Codata.jl
# This file has been automatically generated.

module CODATA
using SIUnits

using SIUnits.ShortUnits

# The PhysicalConstant type encapsulates all of the
# information about a particular constant - the value,
# the uncertainty in that value, the units, and so on.
type PhysicalConstant
	name :: String
	value
	uncertainty
	units_string :: String
end

# autogenerated non-SI units
const MeV = SIUnits.Mega*eV # Mega eV
const GeV = SIUnits.Giga*eV # Giga eV
const fm = SIUnits.Femto*m # femtometers
export AtomicMassUnit
const u = SIUnits.NonSIUnit{typeof(kg), :u}() # AMU
convert(::Type{SIUnits.SIQuantity},::typeof(u))=9.1093826kg
 const T = V*s*m^2
 # Tesla# begin constants

const si_220_lattice_spacing = PhysicalConstant("si_220_lattice_spacing",192.0155714e-12m,0.0000032e-12m,"m")
const alpha_particle_electron_mass_ratio = PhysicalConstant("alpha_particle_electron_mass_ratio",7294.2995361,0.0000029,"")
const alpha_particle_mass = PhysicalConstant("alpha_particle_mass",6.64465675e-27kg,0.00000029e-27kg,"kg")
const alpha_particle_mass_energy_equivalent = PhysicalConstant("alpha_particle_mass_energy_equivalent",5.97191967e-10J,0.00000026e-10J,"J")
const alpha_particle_mass_energy_equivalent_in_mev = PhysicalConstant("alpha_particle_mass_energy_equivalent_in_mev",3727.379240MeV,0.000082MeV,"MeV")
const alpha_particle_mass_in_u = PhysicalConstant("alpha_particle_mass_in_u",4.001506179125u,0.000000000062u,"u")
const alpha_particle_molar_mass = PhysicalConstant("alpha_particle_molar_mass",4.001506179125e-3kg*mol^-1,0.000000000062e-3kg*mol^-1,"kg*mol^-1")
const alpha_particle_proton_mass_ratio = PhysicalConstant("alpha_particle_proton_mass_ratio",3.97259968933,0.00000000036,"")
const angstrom_star = PhysicalConstant("angstrom_star",1.00001495e-10m,0.00000090e-10m,"m")
const atomic_mass_constant = PhysicalConstant("atomic_mass_constant",1.660538921e-27kg,0.000000073e-27kg,"kg")
const atomic_mass_constant_energy_equivalent = PhysicalConstant("atomic_mass_constant_energy_equivalent",1.492417954e-10J,0.000000066e-10J,"J")
const atomic_mass_constant_energy_equivalent_in_mev = PhysicalConstant("atomic_mass_constant_energy_equivalent_in_mev",931.494061MeV,0.000021MeV,"MeV")
const atomic_mass_unit_electron_volt_relationship = PhysicalConstant("atomic_mass_unit_electron_volt_relationship",931.494061e6eV,0.000021e6eV,"eV")
# FIXME atomic_mass_unit_hartree_relationship (E_h)
const atomic_mass_unit_hertz_relationship = PhysicalConstant("atomic_mass_unit_hertz_relationship",2.2523427168e23Hz,0.0000000016e23Hz,"Hz")
const atomic_mass_unit_inverse_meter_relationship = PhysicalConstant("atomic_mass_unit_inverse_meter_relationship",7.5130066042e14m^-1,0.0000000053e14m^-1,"m^-1")
const atomic_mass_unit_joule_relationship = PhysicalConstant("atomic_mass_unit_joule_relationship",1.492417954e-10J,0.000000066e-10J,"J")
const atomic_mass_unit_kelvin_relationship = PhysicalConstant("atomic_mass_unit_kelvin_relationship",1.08095408e13K,0.00000098e13K,"K")
const atomic_mass_unit_kilogram_relationship = PhysicalConstant("atomic_mass_unit_kilogram_relationship",1.660538921e-27kg,0.000000073e-27kg,"kg")
const atomic_unit_of_1st_hyperpolarizability = PhysicalConstant("atomic_unit_of_1st_hyperpolarizability",3.206361449e-53C^3*m^3*J^-2,0.000000071e-53C^3*m^3*J^-2,"C^3*m^3*J^-2")
const atomic_unit_of_2nd_hyperpolarizability = PhysicalConstant("atomic_unit_of_2nd_hyperpolarizability",6.23538054e-65C^4*m^4*J^-3,0.00000028e-65C^4*m^4*J^-3,"C^4*m^4*J^-3")
const atomic_unit_of_action = PhysicalConstant("atomic_unit_of_action",1.054571726e-34J*s,0.000000047e-34J*s,"J*s")
const atomic_unit_of_charge = PhysicalConstant("atomic_unit_of_charge",1.602176565e-19C,0.000000035e-19C,"C")
const atomic_unit_of_charge_density = PhysicalConstant("atomic_unit_of_charge_density",1.081202338e12C*m^-3,0.000000024e12C*m^-3,"C*m^-3")
const atomic_unit_of_current = PhysicalConstant("atomic_unit_of_current",6.62361795e-3A,0.00000015e-3A,"A")
const atomic_unit_of_electric_dipole_mom = PhysicalConstant("atomic_unit_of_electric_dipole_mom",8.47835326e-30C*m,0.00000019e-30C*m,"C*m")
const atomic_unit_of_electric_field = PhysicalConstant("atomic_unit_of_electric_field",5.14220652e11V*m^-1,0.00000011e11V*m^-1,"V*m^-1")
const atomic_unit_of_electric_field_gradient = PhysicalConstant("atomic_unit_of_electric_field_gradient",9.71736200e21V*m^-2,0.00000021e21V*m^-2,"V*m^-2")
const atomic_unit_of_electric_polarizability = PhysicalConstant("atomic_unit_of_electric_polarizability",1.6487772754e-41C^2*m^2*J^-1,0.0000000016e-41C^2*m^2*J^-1,"C^2*m^2*J^-1")
const atomic_unit_of_electric_potential = PhysicalConstant("atomic_unit_of_electric_potential",27.21138505V,0.00000060V,"V")
const atomic_unit_of_electric_quadrupole_mom = PhysicalConstant("atomic_unit_of_electric_quadrupole_mom",4.486551331e-40C*m^2,0.000000099e-40C*m^2,"C*m^2")
const atomic_unit_of_energy = PhysicalConstant("atomic_unit_of_energy",4.35974434e-18J,0.00000019e-18J,"J")
const atomic_unit_of_force = PhysicalConstant("atomic_unit_of_force",8.23872278e-8N,0.00000036e-8N,"N")
const atomic_unit_of_length = PhysicalConstant("atomic_unit_of_length",0.52917721092e-10m,0.00000000017e-10m,"m")
const atomic_unit_of_mag_dipole_mom = PhysicalConstant("atomic_unit_of_mag_dipole_mom",1.854801936e-23J*T^-1,0.000000041e-23J*T^-1,"J*T^-1")
const atomic_unit_of_mag_flux_density = PhysicalConstant("atomic_unit_of_mag_flux_density",2.350517464e5T,0.000000052e5T,"T")
const atomic_unit_of_magnetizability = PhysicalConstant("atomic_unit_of_magnetizability",7.891036607e-29J*T^-2,0.000000013e-29J*T^-2,"J*T^-2")
const atomic_unit_of_mass = PhysicalConstant("atomic_unit_of_mass",9.10938291e-31kg,0.00000040e-31kg,"kg")
const atomic_unit_of_momum = PhysicalConstant("atomic_unit_of_momum",1.992851740e-24kg*m*s^-1,0.000000088e-24kg*m*s^-1,"kg*m*s^-1")
const atomic_unit_of_permittivity = PhysicalConstant("atomic_unit_of_permittivity",1.112650056e-10F*m^-1,0.0F*m^-1,"F*m^-1")
const atomic_unit_of_time = PhysicalConstant("atomic_unit_of_time",2.418884326502e-17s,0.000000000012e-17s,"s")
const atomic_unit_of_velocity = PhysicalConstant("atomic_unit_of_velocity",2.18769126379e6m*s^-1,0.00000000071e6m*s^-1,"m*s^-1")
const avogadro_constant = PhysicalConstant("avogadro_constant",6.02214129e23mol^-1,0.00000027e23mol^-1,"mol^-1")
const bohr_magneton = PhysicalConstant("bohr_magneton",927.400968e-26J*T^-1,0.000020e-26J*T^-1,"J*T^-1")
# FIXME bohr_magneton_in_ev_per_t
const bohr_magneton_in_hz_per_t = PhysicalConstant("bohr_magneton_in_hz_per_t",13.99624555e9Hz*T^-1,0.00000031e9Hz*T^-1,"Hz*T^-1")
const bohr_magneton_in_inverse_meters_per_tesla = PhysicalConstant("bohr_magneton_in_inverse_meters_per_tesla",46.6864498m^-1*T^-1,0.0000010m^-1*T^-1,"m^-1*T^-1")
const bohr_magneton_in_k_per_t = PhysicalConstant("bohr_magneton_in_k_per_t",0.67171388K*T^-1,0.00000061K*T^-1,"K*T^-1")
const bohr_radius = PhysicalConstant("bohr_radius",0.52917721092e-10m,0.00000000017e-10m,"m")
const boltzmann_constant = PhysicalConstant("boltzmann_constant",1.3806488e-23J*K^-1,0.0000013e-23J*K^-1,"J*K^-1")
# FIXME boltzmann_constant_in_ev_per_k
const boltzmann_constant_in_hz_per_k = PhysicalConstant("boltzmann_constant_in_hz_per_k",2.0836618e10Hz*K^-1,0.0000019e10Hz*K^-1,"Hz*K^-1")
const boltzmann_constant_in_inverse_meters_per_kelvin = PhysicalConstant("boltzmann_constant_in_inverse_meters_per_kelvin",69.503476m^-1*K^-1,0.000063m^-1*K^-1,"m^-1*K^-1")
const characteristic_impedance_of_vacuum = PhysicalConstant("characteristic_impedance_of_vacuum",376.730313461Ohm,0.0Ohm,"Ohm")
const classical_electron_radius = PhysicalConstant("classical_electron_radius",2.8179403267e-15m,0.0000000027e-15m,"m")
const compton_wavelength = PhysicalConstant("compton_wavelength",2.4263102389e-12m,0.0000000016e-12m,"m")
const compton_wavelength_over_2_pi = PhysicalConstant("compton_wavelength_over_2_pi",386.15926800e-15m,0.00000025e-15m,"m")
const conductance_quantum = PhysicalConstant("conductance_quantum",7.7480917346e-5S,0.0000000025e-5S,"S")
const conventional_value_of_josephson_constant = PhysicalConstant("conventional_value_of_josephson_constant",483597.9e9Hz*V^-1,0.0Hz*V^-1,"Hz*V^-1")
const conventional_value_of_von_klitzing_constant = PhysicalConstant("conventional_value_of_von_klitzing_constant",25812.807Ohm,0.0Ohm,"Ohm")
const cu_x_unit = PhysicalConstant("cu_x_unit",1.00207697e-13m,0.00000028e-13m,"m")
const deuteron_electron_mag_mom_ratio = PhysicalConstant("deuteron_electron_mag_mom_ratio",-4.664345537e-4,0.000000039e-4,"")
const deuteron_electron_mass_ratio = PhysicalConstant("deuteron_electron_mass_ratio",3670.4829652,0.0000015,"")
const deuteron_g_factor = PhysicalConstant("deuteron_g_factor",0.8574382308,0.0000000072,"")
const deuteron_mag_mom = PhysicalConstant("deuteron_mag_mom",0.433073489e-26J*T^-1,0.000000010e-26J*T^-1,"J*T^-1")
const deuteron_mag_mom_to_bohr_magneton_ratio = PhysicalConstant("deuteron_mag_mom_to_bohr_magneton_ratio",0.4669754556e-3,0.0000000039e-3,"")
const deuteron_mag_mom_to_nuclear_magneton_ratio = PhysicalConstant("deuteron_mag_mom_to_nuclear_magneton_ratio",0.8574382308,0.0000000072,"")
const deuteron_mass = PhysicalConstant("deuteron_mass",3.34358348e-27kg,0.00000015e-27kg,"kg")
const deuteron_mass_energy_equivalent = PhysicalConstant("deuteron_mass_energy_equivalent",3.00506297e-10J,0.00000013e-10J,"J")
const deuteron_mass_energy_equivalent_in_mev = PhysicalConstant("deuteron_mass_energy_equivalent_in_mev",1875.612859MeV,0.000041MeV,"MeV")
const deuteron_mass_in_u = PhysicalConstant("deuteron_mass_in_u",2.013553212712u,0.000000000077u,"u")
const deuteron_molar_mass = PhysicalConstant("deuteron_molar_mass",2.013553212712e-3kg*mol^-1,0.000000000077e-3kg*mol^-1,"kg*mol^-1")
const deuteron_neutron_mag_mom_ratio = PhysicalConstant("deuteron_neutron_mag_mom_ratio",-0.44820652,0.00000011,"")
const deuteron_proton_mag_mom_ratio = PhysicalConstant("deuteron_proton_mag_mom_ratio",0.3070122070,0.0000000024,"")
const deuteron_proton_mass_ratio = PhysicalConstant("deuteron_proton_mass_ratio",1.99900750097,0.00000000018,"")
const deuteron_rms_charge_radius = PhysicalConstant("deuteron_rms_charge_radius",2.1424e-15m,0.0021e-15m,"m")
const electric_constant = PhysicalConstant("electric_constant",8.854187817e-12F*m^-1,0.0F*m^-1,"F*m^-1")
const electron_charge_to_mass_quotient = PhysicalConstant("electron_charge_to_mass_quotient",-1.758820088e11C*kg^-1,0.000000039e11C*kg^-1,"C*kg^-1")
const electron_deuteron_mag_mom_ratio = PhysicalConstant("electron_deuteron_mag_mom_ratio",-2143.923498,0.000018,"")
const electron_deuteron_mass_ratio = PhysicalConstant("electron_deuteron_mass_ratio",2.7244371095e-4,0.0000000011e-4,"")
const electron_g_factor = PhysicalConstant("electron_g_factor",-2.00231930436153,0.00000000000053,"")
const electron_gyromag_ratio = PhysicalConstant("electron_gyromag_ratio",1.760859708e11s^-1*T^-1,0.000000039e11s^-1*T^-1,"s^-1*T^-1")
const electron_gyromag_ratio_over_2_pi = PhysicalConstant("electron_gyromag_ratio_over_2_pi",28024.95266MHz*T^-1,0.00062MHz*T^-1,"MHz*T^-1")
const electron_helion_mass_ratio = PhysicalConstant("electron_helion_mass_ratio",1.8195430761e-4,0.0000000017e-4,"")
const electron_mag_mom = PhysicalConstant("electron_mag_mom",-928.476430e-26J*T^-1,0.000021e-26J*T^-1,"J*T^-1")
const electron_mag_mom_anomaly = PhysicalConstant("electron_mag_mom_anomaly",1.15965218076e-3,0.00000000027e-3,"")
const electron_mag_mom_to_bohr_magneton_ratio = PhysicalConstant("electron_mag_mom_to_bohr_magneton_ratio",-1.00115965218076,0.00000000000027,"")
const electron_mag_mom_to_nuclear_magneton_ratio = PhysicalConstant("electron_mag_mom_to_nuclear_magneton_ratio",-1838.28197090,0.00000075,"")
const electron_mass = PhysicalConstant("electron_mass",9.10938291e-31kg,0.00000040e-31kg,"kg")
const electron_mass_energy_equivalent = PhysicalConstant("electron_mass_energy_equivalent",8.18710506e-14J,0.00000036e-14J,"J")
const electron_mass_energy_equivalent_in_mev = PhysicalConstant("electron_mass_energy_equivalent_in_mev",0.510998928MeV,0.000000011MeV,"MeV")
const electron_mass_in_u = PhysicalConstant("electron_mass_in_u",5.4857990946e-4u,0.0000000022e-4u,"u")
const electron_molar_mass = PhysicalConstant("electron_molar_mass",5.4857990946e-7kg*mol^-1,0.0000000022e-7kg*mol^-1,"kg*mol^-1")
const electron_muon_mag_mom_ratio = PhysicalConstant("electron_muon_mag_mom_ratio",206.7669896,0.0000052,"")
const electron_muon_mass_ratio = PhysicalConstant("electron_muon_mass_ratio",4.83633166e-3,0.00000012e-3,"")
const electron_neutron_mag_mom_ratio = PhysicalConstant("electron_neutron_mag_mom_ratio",960.92050,0.00023,"")
const electron_neutron_mass_ratio = PhysicalConstant("electron_neutron_mass_ratio",5.4386734461e-4,0.0000000032e-4,"")
const electron_proton_mag_mom_ratio = PhysicalConstant("electron_proton_mag_mom_ratio",-658.2106848,0.0000054,"")
const electron_proton_mass_ratio = PhysicalConstant("electron_proton_mass_ratio",5.4461702178e-4,0.0000000022e-4,"")
const electron_tau_mass_ratio = PhysicalConstant("electron_tau_mass_ratio",2.87592e-4,0.00026e-4,"")
const electron_to_alpha_particle_mass_ratio = PhysicalConstant("electron_to_alpha_particle_mass_ratio",1.37093355578e-4,0.00000000055e-4,"")
const electron_to_shielded_helion_mag_mom_ratio = PhysicalConstant("electron_to_shielded_helion_mag_mom_ratio",864.058257,0.000010,"")
const electron_to_shielded_proton_mag_mom_ratio = PhysicalConstant("electron_to_shielded_proton_mag_mom_ratio",-658.2275971,0.0000072,"")
const electron_triton_mass_ratio = PhysicalConstant("electron_triton_mass_ratio",1.8192000653e-4,0.0000000017e-4,"")
const electron_volt = PhysicalConstant("electron_volt",1.602176565e-19J,0.000000035e-19J,"J")
const electron_volt_atomic_mass_unit_relationship = PhysicalConstant("electron_volt_atomic_mass_unit_relationship",1.073544150e-9u,0.000000024e-9u,"u")
# FIXME electron_volt_hartree_relationship (E_h)
const electron_volt_hertz_relationship = PhysicalConstant("electron_volt_hertz_relationship",2.417989348e14Hz,0.000000053e14Hz,"Hz")
const electron_volt_inverse_meter_relationship = PhysicalConstant("electron_volt_inverse_meter_relationship",8.06554429e5m^-1,0.00000018e5m^-1,"m^-1")
const electron_volt_joule_relationship = PhysicalConstant("electron_volt_joule_relationship",1.602176565e-19J,0.000000035e-19J,"J")
const electron_volt_kelvin_relationship = PhysicalConstant("electron_volt_kelvin_relationship",1.1604519e4K,0.0000011e4K,"K")
const electron_volt_kilogram_relationship = PhysicalConstant("electron_volt_kilogram_relationship",1.782661845e-36kg,0.000000039e-36kg,"kg")
const elementary_charge = PhysicalConstant("elementary_charge",1.602176565e-19C,0.000000035e-19C,"C")
const elementary_charge_over_h = PhysicalConstant("elementary_charge_over_h",2.417989348e14A*J^-1,0.000000053e14A*J^-1,"A*J^-1")
const faraday_constant = PhysicalConstant("faraday_constant",96485.3365C*mol^-1,0.0021C*mol^-1,"C*mol^-1")
# FIXME faraday_constant_for_conventional_electric_current (C_90*mol^-1)
const fermi_coupling_constant = PhysicalConstant("fermi_coupling_constant",1.166364e-5GeV^-2,0.000005e-5GeV^-2,"GeV^-2")
const fine_structure_constant = PhysicalConstant("fine_structure_constant",7.2973525698e-3,0.0000000024e-3,"")
const first_radiation_constant = PhysicalConstant("first_radiation_constant",3.74177153e-16W*m^2,0.00000017e-16W*m^2,"W*m^2")
# FIXME first_radiation_constant_for_spectral_radiance (W*m^2*sr^-1)
const hartree_atomic_mass_unit_relationship = PhysicalConstant("hartree_atomic_mass_unit_relationship",2.9212623246e-8u,0.0000000021e-8u,"u")
const hartree_electron_volt_relationship = PhysicalConstant("hartree_electron_volt_relationship",27.21138505eV,0.00000060eV,"eV")
const hartree_energy = PhysicalConstant("hartree_energy",4.35974434e-18J,0.00000019e-18J,"J")
const hartree_energy_in_ev = PhysicalConstant("hartree_energy_in_ev",27.21138505eV,0.00000060eV,"eV")
const hartree_hertz_relationship = PhysicalConstant("hartree_hertz_relationship",6.579683920729e15Hz,0.000000000033e15Hz,"Hz")
const hartree_inverse_meter_relationship = PhysicalConstant("hartree_inverse_meter_relationship",2.194746313708e7m^-1,0.000000000011e7m^-1,"m^-1")
const hartree_joule_relationship = PhysicalConstant("hartree_joule_relationship",4.35974434e-18J,0.00000019e-18J,"J")
const hartree_kelvin_relationship = PhysicalConstant("hartree_kelvin_relationship",3.1577504e5K,0.0000029e5K,"K")
const hartree_kilogram_relationship = PhysicalConstant("hartree_kilogram_relationship",4.85086979e-35kg,0.00000021e-35kg,"kg")
const helion_electron_mass_ratio = PhysicalConstant("helion_electron_mass_ratio",5495.8852754,0.0000050,"")
const helion_g_factor = PhysicalConstant("helion_g_factor",-4.255250613,0.000000050,"")
const helion_mag_mom = PhysicalConstant("helion_mag_mom",-1.074617486e-26J*T^-1,0.000000027e-26J*T^-1,"J*T^-1")
const helion_mag_mom_to_bohr_magneton_ratio = PhysicalConstant("helion_mag_mom_to_bohr_magneton_ratio",-1.158740958e-3,0.000000014e-3,"")
const helion_mag_mom_to_nuclear_magneton_ratio = PhysicalConstant("helion_mag_mom_to_nuclear_magneton_ratio",-2.127625306,0.000000025,"")
const helion_mass = PhysicalConstant("helion_mass",5.00641234e-27kg,0.00000022e-27kg,"kg")
const helion_mass_energy_equivalent = PhysicalConstant("helion_mass_energy_equivalent",4.49953902e-10J,0.00000020e-10J,"J")
const helion_mass_energy_equivalent_in_mev = PhysicalConstant("helion_mass_energy_equivalent_in_mev",2808.391482MeV,0.000062MeV,"MeV")
const helion_mass_in_u = PhysicalConstant("helion_mass_in_u",3.0149322468u,0.0000000025u,"u")
const helion_molar_mass = PhysicalConstant("helion_molar_mass",3.0149322468e-3kg*mol^-1,0.0000000025e-3kg*mol^-1,"kg*mol^-1")
const helion_proton_mass_ratio = PhysicalConstant("helion_proton_mass_ratio",2.9931526707,0.0000000025,"")
const hertz_atomic_mass_unit_relationship = PhysicalConstant("hertz_atomic_mass_unit_relationship",4.4398216689e-24u,0.0000000031e-24u,"u")
const hertz_electron_volt_relationship = PhysicalConstant("hertz_electron_volt_relationship",4.135667516e-15eV,0.000000091e-15eV,"eV")
# FIXME hertz_hartree_relationship (6*E_h)
const hertz_inverse_meter_relationship = PhysicalConstant("hertz_inverse_meter_relationship",3.335640951e-9m^-1,0.0m^-1,"m^-1")
const hertz_joule_relationship = PhysicalConstant("hertz_joule_relationship",6.62606957e-34J,0.00000029e-34J,"J")
const hertz_kelvin_relationship = PhysicalConstant("hertz_kelvin_relationship",4.7992434e-11K,0.0000044e-11K,"K")
const hertz_kilogram_relationship = PhysicalConstant("hertz_kilogram_relationship",7.37249668e-51kg,0.00000033e-51kg,"kg")
const inverse_fine_structure_constant = PhysicalConstant("inverse_fine_structure_constant",137.035999074,0.000000044,"")
const inverse_meter_atomic_mass_unit_relationship = PhysicalConstant("inverse_meter_atomic_mass_unit_relationship",1.33102505120e-15u,0.00000000094e-15u,"u")
const inverse_meter_electron_volt_relationship = PhysicalConstant("inverse_meter_electron_volt_relationship",1.239841930e-6eV,0.000000027e-6eV,"eV")
# FIXME inverse_meter_hartree_relationship (E_h)
const inverse_meter_hertz_relationship = PhysicalConstant("inverse_meter_hertz_relationship",299792458Hz,0.0Hz,"Hz")
const inverse_meter_joule_relationship = PhysicalConstant("inverse_meter_joule_relationship",1.986445684e-25J,0.000000088e-25J,"J")
const inverse_meter_kelvin_relationship = PhysicalConstant("inverse_meter_kelvin_relationship",1.4387770e-2K,0.0000013e-2K,"K")
const inverse_meter_kilogram_relationship = PhysicalConstant("inverse_meter_kilogram_relationship",2.210218902e-42kg,0.000000098e-42kg,"kg")
const inverse_of_conductance_quantum = PhysicalConstant("inverse_of_conductance_quantum",12906.4037217Ohm,0.0000042Ohm,"Ohm")
const josephson_constant = PhysicalConstant("josephson_constant",483597.870e9Hz*V^-1,0.011e9Hz*V^-1,"Hz*V^-1")
const joule_atomic_mass_unit_relationship = PhysicalConstant("joule_atomic_mass_unit_relationship",6.70053585e9u,0.00000030e9u,"u")
const joule_electron_volt_relationship = PhysicalConstant("joule_electron_volt_relationship",6.24150934e18eV,0.00000014e18eV,"eV")
# FIXME joule_hartree_relationship (E_h)
const joule_hertz_relationship = PhysicalConstant("joule_hertz_relationship",1.509190311e33Hz,0.000000067e33Hz,"Hz")
const joule_inverse_meter_relationship = PhysicalConstant("joule_inverse_meter_relationship",5.03411701e24m^-1,0.00000022e24m^-1,"m^-1")
const joule_kelvin_relationship = PhysicalConstant("joule_kelvin_relationship",7.2429716e22K,0.0000066e22K,"K")
const joule_kilogram_relationship = PhysicalConstant("joule_kilogram_relationship",1.112650056e-17kg,0.0kg,"kg")
const kelvin_atomic_mass_unit_relationship = PhysicalConstant("kelvin_atomic_mass_unit_relationship",9.2510868e-14u,0.0000084e-14u,"u")
const kelvin_electron_volt_relationship = PhysicalConstant("kelvin_electron_volt_relationship",8.6173324e-5eV,0.0000078e-5eV,"eV")
# FIXME kelvin_hartree_relationship (E_h)
const kelvin_hertz_relationship = PhysicalConstant("kelvin_hertz_relationship",2.0836618e10Hz,0.0000019e10Hz,"Hz")
const kelvin_inverse_meter_relationship = PhysicalConstant("kelvin_inverse_meter_relationship",69.503476m^-1,0.000063m^-1,"m^-1")
const kelvin_joule_relationship = PhysicalConstant("kelvin_joule_relationship",1.3806488e-23J,0.0000013e-23J,"J")
const kelvin_kilogram_relationship = PhysicalConstant("kelvin_kilogram_relationship",1.5361790e-40kg,0.0000014e-40kg,"kg")
const kilogram_atomic_mass_unit_relationship = PhysicalConstant("kilogram_atomic_mass_unit_relationship",6.02214129e26u,0.00000027e26u,"u")
const kilogram_electron_volt_relationship = PhysicalConstant("kilogram_electron_volt_relationship",5.60958885e35eV,0.00000012e35eV,"eV")
# FIXME kilogram_hartree_relationship (E_h)
const kilogram_hertz_relationship = PhysicalConstant("kilogram_hertz_relationship",1.356392608e50Hz,0.000000060e50Hz,"Hz")
const kilogram_inverse_meter_relationship = PhysicalConstant("kilogram_inverse_meter_relationship",4.52443873e41m^-1,0.00000020e41m^-1,"m^-1")
const kilogram_joule_relationship = PhysicalConstant("kilogram_joule_relationship",8.987551787e16J,0.0J,"J")
const kilogram_kelvin_relationship = PhysicalConstant("kilogram_kelvin_relationship",6.5096582e39K,0.0000059e39K,"K")
const lattice_parameter_of_silicon = PhysicalConstant("lattice_parameter_of_silicon",543.1020504e-12m,0.0000089e-12m,"m")
const loschmidt_constant__27315_k__100_kpa = PhysicalConstant("loschmidt_constant__27315_k__100_kpa",2.6516462e25m^-3,0.0000024e25m^-3,"m^-3")
const loschmidt_constant__27315_k__101325_kpa = PhysicalConstant("loschmidt_constant__27315_k__101325_kpa",2.6867805e25m^-3,0.0000024e25m^-3,"m^-3")
const mag_constant = PhysicalConstant("mag_constant",12.566370614e-7N*A^-2,0.0N*A^-2,"N*A^-2")
# FIXME mag_flux_quantum (Wb)
const molar_gas_constant = PhysicalConstant("molar_gas_constant",8.3144621J*mol^-1*K^-1,0.0000075J*mol^-1*K^-1,"J*mol^-1*K^-1")
const molar_mass_constant = PhysicalConstant("molar_mass_constant",1e-3kg*mol^-1,0.0kg*mol^-1,"kg*mol^-1")
const molar_mass_of_carbon_12 = PhysicalConstant("molar_mass_of_carbon_12",12e-3kg*mol^-1,0.0kg*mol^-1,"kg*mol^-1")
const molar_planck_constant = PhysicalConstant("molar_planck_constant",3.9903127176e-10J*s*mol^-1,0.0000000028e-10J*s*mol^-1,"J*s*mol^-1")
const molar_planck_constant_times_c = PhysicalConstant("molar_planck_constant_times_c",0.119626565779J*m*mol^-1,0.000000000084J*m*mol^-1,"J*m*mol^-1")
const molar_volume_of_ideal_gas__27315_k__100_kpa = PhysicalConstant("molar_volume_of_ideal_gas__27315_k__100_kpa",22.710953e-3m^3*mol^-1,0.000021e-3m^3*mol^-1,"m^3*mol^-1")
const molar_volume_of_ideal_gas__27315_k__101325_kpa = PhysicalConstant("molar_volume_of_ideal_gas__27315_k__101325_kpa",22.413968e-3m^3*mol^-1,0.000020e-3m^3*mol^-1,"m^3*mol^-1")
const molar_volume_of_silicon = PhysicalConstant("molar_volume_of_silicon",12.05883301e-6m^3*mol^-1,0.00000080e-6m^3*mol^-1,"m^3*mol^-1")
const mo_x_unit = PhysicalConstant("mo_x_unit",1.00209952e-13m,0.00000053e-13m,"m")
const muon_compton_wavelength = PhysicalConstant("muon_compton_wavelength",11.73444103e-15m,0.00000030e-15m,"m")
const muon_compton_wavelength_over_2_pi = PhysicalConstant("muon_compton_wavelength_over_2_pi",1.867594294e-15m,0.000000047e-15m,"m")
const muon_electron_mass_ratio = PhysicalConstant("muon_electron_mass_ratio",206.7682843,0.0000052,"")
const muon_g_factor = PhysicalConstant("muon_g_factor",-2.0023318418,0.0000000013,"")
const muon_mag_mom = PhysicalConstant("muon_mag_mom",-4.49044807e-26J*T^-1,0.00000015e-26J*T^-1,"J*T^-1")
const muon_mag_mom_anomaly = PhysicalConstant("muon_mag_mom_anomaly",1.16592091e-3,0.00000063e-3,"")
const muon_mag_mom_to_bohr_magneton_ratio = PhysicalConstant("muon_mag_mom_to_bohr_magneton_ratio",-4.84197044e-3,0.00000012e-3,"")
const muon_mag_mom_to_nuclear_magneton_ratio = PhysicalConstant("muon_mag_mom_to_nuclear_magneton_ratio",-8.89059697,0.00000022,"")
const muon_mass = PhysicalConstant("muon_mass",1.883531475e-28kg,0.000000096e-28kg,"kg")
const muon_mass_energy_equivalent = PhysicalConstant("muon_mass_energy_equivalent",1.692833667e-11J,0.000000086e-11J,"J")
const muon_mass_energy_equivalent_in_mev = PhysicalConstant("muon_mass_energy_equivalent_in_mev",105.6583715MeV,0.0000035MeV,"MeV")
const muon_mass_in_u = PhysicalConstant("muon_mass_in_u",0.1134289267u,0.0000000029u,"u")
const muon_molar_mass = PhysicalConstant("muon_molar_mass",0.1134289267e-3kg*mol^-1,0.0000000029e-3kg*mol^-1,"kg*mol^-1")
const muon_neutron_mass_ratio = PhysicalConstant("muon_neutron_mass_ratio",0.1124545177,0.0000000028,"")
const muon_proton_mag_mom_ratio = PhysicalConstant("muon_proton_mag_mom_ratio",-3.183345107,0.000000084,"")
const muon_proton_mass_ratio = PhysicalConstant("muon_proton_mass_ratio",0.1126095272,0.0000000028,"")
const muon_tau_mass_ratio = PhysicalConstant("muon_tau_mass_ratio",5.94649e-2,0.00054e-2,"")
const natural_unit_of_action = PhysicalConstant("natural_unit_of_action",1.054571726e-34J*s,0.000000047e-34J*s,"J*s")
# FIXME natural_unit_of_action_in_ev_s
const natural_unit_of_energy = PhysicalConstant("natural_unit_of_energy",8.18710506e-14J,0.00000036e-14J,"J")
const natural_unit_of_energy_in_mev = PhysicalConstant("natural_unit_of_energy_in_mev",0.510998928MeV,0.000000011MeV,"MeV")
const natural_unit_of_length = PhysicalConstant("natural_unit_of_length",386.15926800e-15m,0.00000025e-15m,"m")
const natural_unit_of_mass = PhysicalConstant("natural_unit_of_mass",9.10938291e-31kg,0.00000040e-31kg,"kg")
const natural_unit_of_momum = PhysicalConstant("natural_unit_of_momum",2.73092429e-22kg*m*s^-1,0.00000012e-22kg*m*s^-1,"kg*m*s^-1")
# FIXME natural_unit_of_momum_in_mev_per_c (MeV/c)
const natural_unit_of_time = PhysicalConstant("natural_unit_of_time",1.28808866833e-21s,0.00000000083e-21s,"s")
const natural_unit_of_velocity = PhysicalConstant("natural_unit_of_velocity",299792458m*s^-1,0.0m*s^-1,"m*s^-1")
const neutron_compton_wavelength = PhysicalConstant("neutron_compton_wavelength",1.3195909068e-15m,0.0000000011e-15m,"m")
const neutron_compton_wavelength_over_2_pi = PhysicalConstant("neutron_compton_wavelength_over_2_pi",0.21001941568e-15m,0.00000000017e-15m,"m")
const neutron_electron_mag_mom_ratio = PhysicalConstant("neutron_electron_mag_mom_ratio",1.04066882e-3,0.00000025e-3,"")
const neutron_electron_mass_ratio = PhysicalConstant("neutron_electron_mass_ratio",1838.6836605,0.0000011,"")
const neutron_g_factor = PhysicalConstant("neutron_g_factor",-3.82608545,0.00000090,"")
const neutron_gyromag_ratio = PhysicalConstant("neutron_gyromag_ratio",1.83247179e8s^-1*T^-1,0.00000043e8s^-1*T^-1,"s^-1*T^-1")
const neutron_gyromag_ratio_over_2_pi = PhysicalConstant("neutron_gyromag_ratio_over_2_pi",29.1646943MHz*T^-1,0.0000069MHz*T^-1,"MHz*T^-1")
const neutron_mag_mom = PhysicalConstant("neutron_mag_mom",-0.96623647e-26J*T^-1,0.00000023e-26J*T^-1,"J*T^-1")
const neutron_mag_mom_to_bohr_magneton_ratio = PhysicalConstant("neutron_mag_mom_to_bohr_magneton_ratio",-1.04187563e-3,0.00000025e-3,"")
const neutron_mag_mom_to_nuclear_magneton_ratio = PhysicalConstant("neutron_mag_mom_to_nuclear_magneton_ratio",-1.91304272,0.00000045,"")
const neutron_mass = PhysicalConstant("neutron_mass",1.674927351e-27kg,0.000000074e-27kg,"kg")
const neutron_mass_energy_equivalent = PhysicalConstant("neutron_mass_energy_equivalent",1.505349631e-10J,0.000000066e-10J,"J")
const neutron_mass_energy_equivalent_in_mev = PhysicalConstant("neutron_mass_energy_equivalent_in_mev",939.565379MeV,0.000021MeV,"MeV")
const neutron_mass_in_u = PhysicalConstant("neutron_mass_in_u",1.00866491600u,0.00000000043u,"u")
const neutron_molar_mass = PhysicalConstant("neutron_molar_mass",1.00866491600e-3kg*mol^-1,0.00000000043e-3kg*mol^-1,"kg*mol^-1")
const neutron_muon_mass_ratio = PhysicalConstant("neutron_muon_mass_ratio",8.89248400,0.00000022,"")
const neutron_proton_mag_mom_ratio = PhysicalConstant("neutron_proton_mag_mom_ratio",-0.68497934,0.00000016,"")
const neutron_proton_mass_difference = PhysicalConstant("neutron_proton_mass_difference",2.30557392e-30,0.00000076e-30,"")
const neutron_proton_mass_difference_energy_equivalent = PhysicalConstant("neutron_proton_mass_difference_energy_equivalent",2.07214650e-13,0.00000068e-13,"")
const neutron_proton_mass_difference_energy_equivalent_in_mev = PhysicalConstant("neutron_proton_mass_difference_energy_equivalent_in_mev",1.29333217,0.00000042,"")
const neutron_proton_mass_difference_in_u = PhysicalConstant("neutron_proton_mass_difference_in_u",0.00138844919,0.00000000045,"")
const neutron_proton_mass_ratio = PhysicalConstant("neutron_proton_mass_ratio",1.00137841917,0.00000000045,"")
const neutron_tau_mass_ratio = PhysicalConstant("neutron_tau_mass_ratio",0.528790,0.000048,"")
const neutron_to_shielded_proton_mag_mom_ratio = PhysicalConstant("neutron_to_shielded_proton_mag_mom_ratio",-0.68499694,0.00000016,"")
const newtonian_constant_of_gravitation = PhysicalConstant("newtonian_constant_of_gravitation",6.67384e-11m^3*kg^-1*s^-2,0.00080e-11m^3*kg^-1*s^-2,"m^3*kg^-1*s^-2")
# FIXME newtonian_constant_of_gravitation_over_h_bar_c ((GeV/c^2)^-2)
const nuclear_magneton = PhysicalConstant("nuclear_magneton",5.05078353e-27J*T^-1,0.00000011e-27J*T^-1,"J*T^-1")
# FIXME nuclear_magneton_in_ev_per_t
const nuclear_magneton_in_inverse_meters_per_tesla = PhysicalConstant("nuclear_magneton_in_inverse_meters_per_tesla",2.542623527e-2m^-1*T^-1,0.000000056e-2m^-1*T^-1,"m^-1*T^-1")
const nuclear_magneton_in_k_per_t = PhysicalConstant("nuclear_magneton_in_k_per_t",3.6582682e-4K*T^-1,0.0000033e-4K*T^-1,"K*T^-1")
const nuclear_magneton_in_mhz_per_t = PhysicalConstant("nuclear_magneton_in_mhz_per_t",7.62259357MHz*T^-1,0.00000017MHz*T^-1,"MHz*T^-1")
const planck_constant = PhysicalConstant("planck_constant",6.62606957e-34J*s,0.00000029e-34J*s,"J*s")
# FIXME planck_constant_in_ev_s
const planck_constant_over_2_pi = PhysicalConstant("planck_constant_over_2_pi",1.054571726e-34J*s,0.000000047e-34J*s,"J*s")
# FIXME planck_constant_over_2_pi_in_ev_s
const planck_constant_over_2_pi_times_c_in_mev_fm = PhysicalConstant("planck_constant_over_2_pi_times_c_in_mev_fm",197.3269718MeV*fm,0.0000044MeV*fm,"MeV*fm")
const planck_length = PhysicalConstant("planck_length",1.616199e-35m,0.000097e-35m,"m")
const planck_mass = PhysicalConstant("planck_mass",2.17651e-8kg,0.00013e-8kg,"kg")
const planck_mass_energy_equivalent_in_gev = PhysicalConstant("planck_mass_energy_equivalent_in_gev",1.220932e19GeV,0.000073e19GeV,"GeV")
const planck_temperature = PhysicalConstant("planck_temperature",1.416833e32K,0.000085e32K,"K")
const planck_time = PhysicalConstant("planck_time",5.39106e-44s,0.00032e-44s,"s")
const proton_charge_to_mass_quotient = PhysicalConstant("proton_charge_to_mass_quotient",9.57883358e7C*kg^-1,0.00000021e7C*kg^-1,"C*kg^-1")
const proton_compton_wavelength = PhysicalConstant("proton_compton_wavelength",1.32140985623e-15m,0.00000000094e-15m,"m")
const proton_compton_wavelength_over_2_pi = PhysicalConstant("proton_compton_wavelength_over_2_pi",0.21030891047e-15m,0.00000000015e-15m,"m")
const proton_electron_mass_ratio = PhysicalConstant("proton_electron_mass_ratio",1836.15267245,0.00000075,"")
const proton_g_factor = PhysicalConstant("proton_g_factor",5.585694713,0.000000046,"")
const proton_gyromag_ratio = PhysicalConstant("proton_gyromag_ratio",2.675222005e8s^-1*T^-1,0.000000063e8s^-1*T^-1,"s^-1*T^-1")
const proton_gyromag_ratio_over_2_pi = PhysicalConstant("proton_gyromag_ratio_over_2_pi",42.5774806MHz*T^-1,0.0000010MHz*T^-1,"MHz*T^-1")
const proton_mag_mom = PhysicalConstant("proton_mag_mom",1.410606743e-26J*T^-1,0.000000033e-26J*T^-1,"J*T^-1")
const proton_mag_mom_to_bohr_magneton_ratio = PhysicalConstant("proton_mag_mom_to_bohr_magneton_ratio",1.521032210e-3,0.000000012e-3,"")
const proton_mag_mom_to_nuclear_magneton_ratio = PhysicalConstant("proton_mag_mom_to_nuclear_magneton_ratio",2.792847356,0.000000023,"")
const proton_mag_shielding_correction = PhysicalConstant("proton_mag_shielding_correction",25.694e-6,0.014e-6,"")
const proton_mass = PhysicalConstant("proton_mass",1.672621777e-27kg,0.000000074e-27kg,"kg")
const proton_mass_energy_equivalent = PhysicalConstant("proton_mass_energy_equivalent",1.503277484e-10J,0.000000066e-10J,"J")
const proton_mass_energy_equivalent_in_mev = PhysicalConstant("proton_mass_energy_equivalent_in_mev",938.272046MeV,0.000021MeV,"MeV")
const proton_mass_in_u = PhysicalConstant("proton_mass_in_u",1.007276466812u,0.000000000090u,"u")
const proton_molar_mass = PhysicalConstant("proton_molar_mass",1.007276466812e-3kg*mol^-1,0.000000000090e-3kg*mol^-1,"kg*mol^-1")
const proton_muon_mass_ratio = PhysicalConstant("proton_muon_mass_ratio",8.88024331,0.00000022,"")
const proton_neutron_mag_mom_ratio = PhysicalConstant("proton_neutron_mag_mom_ratio",-1.45989806,0.00000034,"")
const proton_neutron_mass_ratio = PhysicalConstant("proton_neutron_mass_ratio",0.99862347826,0.00000000045,"")
const proton_rms_charge_radius = PhysicalConstant("proton_rms_charge_radius",0.8775e-15m,0.0051e-15m,"m")
const proton_tau_mass_ratio = PhysicalConstant("proton_tau_mass_ratio",0.528063,0.000048,"")
const quantum_of_circulation = PhysicalConstant("quantum_of_circulation",3.6369475520e-4m^2*s^-1,0.0000000024e-4m^2*s^-1,"m^2*s^-1")
const quantum_of_circulation_times_2 = PhysicalConstant("quantum_of_circulation_times_2",7.2738951040e-4m^2*s^-1,0.0000000047e-4m^2*s^-1,"m^2*s^-1")
const rydberg_constant = PhysicalConstant("rydberg_constant",10973731.568539m^-1,0.000055m^-1,"m^-1")
const rydberg_constant_times_c_in_hz = PhysicalConstant("rydberg_constant_times_c_in_hz",3.289841960364e15Hz,0.000000000017e15Hz,"Hz")
const rydberg_constant_times_hc_in_ev = PhysicalConstant("rydberg_constant_times_hc_in_ev",13.60569253eV,0.00000030eV,"eV")
const rydberg_constant_times_hc_in_j = PhysicalConstant("rydberg_constant_times_hc_in_j",2.179872171e-18J,0.000000096e-18J,"J")
const sackur_tetrode_constant__1_k__100_kpa = PhysicalConstant("sackur_tetrode_constant__1_k__100_kpa",-1.1517078,0.0000023,"")
const sackur_tetrode_constant__1_k__101325_kpa = PhysicalConstant("sackur_tetrode_constant__1_k__101325_kpa",-1.1648708,0.0000023,"")
const second_radiation_constant = PhysicalConstant("second_radiation_constant",1.4387770e-2m*K,0.0000013e-2m*K,"m*K")
const shielded_helion_gyromag_ratio = PhysicalConstant("shielded_helion_gyromag_ratio",2.037894659e8s^-1*T^-1,0.000000051e8s^-1*T^-1,"s^-1*T^-1")
const shielded_helion_gyromag_ratio_over_2_pi = PhysicalConstant("shielded_helion_gyromag_ratio_over_2_pi",32.43410084MHz*T^-1,0.00000081MHz*T^-1,"MHz*T^-1")
const shielded_helion_mag_mom = PhysicalConstant("shielded_helion_mag_mom",-1.074553044e-26J*T^-1,0.000000027e-26J*T^-1,"J*T^-1")
const shielded_helion_mag_mom_to_bohr_magneton_ratio = PhysicalConstant("shielded_helion_mag_mom_to_bohr_magneton_ratio",-1.158671471e-3,0.000000014e-3,"")
const shielded_helion_mag_mom_to_nuclear_magneton_ratio = PhysicalConstant("shielded_helion_mag_mom_to_nuclear_magneton_ratio",-2.127497718,0.000000025,"")
const shielded_helion_to_proton_mag_mom_ratio = PhysicalConstant("shielded_helion_to_proton_mag_mom_ratio",-0.761766558,0.000000011,"")
const shielded_helion_to_shielded_proton_mag_mom_ratio = PhysicalConstant("shielded_helion_to_shielded_proton_mag_mom_ratio",-0.7617861313,0.0000000033,"")
const shielded_proton_gyromag_ratio = PhysicalConstant("shielded_proton_gyromag_ratio",2.675153268e8s^-1*T^-1,0.000000066e8s^-1*T^-1,"s^-1*T^-1")
const shielded_proton_gyromag_ratio_over_2_pi = PhysicalConstant("shielded_proton_gyromag_ratio_over_2_pi",42.5763866MHz*T^-1,0.0000010MHz*T^-1,"MHz*T^-1")
const shielded_proton_mag_mom = PhysicalConstant("shielded_proton_mag_mom",1.410570499e-26J*T^-1,0.000000035e-26J*T^-1,"J*T^-1")
const shielded_proton_mag_mom_to_bohr_magneton_ratio = PhysicalConstant("shielded_proton_mag_mom_to_bohr_magneton_ratio",1.520993128e-3,0.000000017e-3,"")
const shielded_proton_mag_mom_to_nuclear_magneton_ratio = PhysicalConstant("shielded_proton_mag_mom_to_nuclear_magneton_ratio",2.792775598,0.000000030,"")
const speed_of_light_in_vacuum = PhysicalConstant("speed_of_light_in_vacuum",299792458m*s^-1,0.0m*s^-1,"m*s^-1")
const standard_acceleration_of_gravity = PhysicalConstant("standard_acceleration_of_gravity",9.80665m*s^-2,0.0m*s^-2,"m*s^-2")
const standard_atmosphere = PhysicalConstant("standard_atmosphere",101325Pa,0.0Pa,"Pa")
const standard_state_pressure = PhysicalConstant("standard_state_pressure",100000Pa,0.0Pa,"Pa")
const stefan_boltzmann_constant = PhysicalConstant("stefan_boltzmann_constant",5.670373e-8W*m^-2*K^-4,0.000021e-8W*m^-2*K^-4,"W*m^-2*K^-4")
const tau_compton_wavelength = PhysicalConstant("tau_compton_wavelength",0.697787e-15m,0.000063e-15m,"m")
const tau_compton_wavelength_over_2_pi = PhysicalConstant("tau_compton_wavelength_over_2_pi",0.111056e-15m,0.000010e-15m,"m")
const tau_electron_mass_ratio = PhysicalConstant("tau_electron_mass_ratio",3477.15,0.31,"")
const tau_mass = PhysicalConstant("tau_mass",3.16747e-27kg,0.00029e-27kg,"kg")
const tau_mass_energy_equivalent = PhysicalConstant("tau_mass_energy_equivalent",2.84678e-10J,0.00026e-10J,"J")
const tau_mass_energy_equivalent_in_mev = PhysicalConstant("tau_mass_energy_equivalent_in_mev",1776.82MeV,0.16MeV,"MeV")
const tau_mass_in_u = PhysicalConstant("tau_mass_in_u",1.90749u,0.00017u,"u")
const tau_molar_mass = PhysicalConstant("tau_molar_mass",1.90749e-3kg*mol^-1,0.00017e-3kg*mol^-1,"kg*mol^-1")
const tau_muon_mass_ratio = PhysicalConstant("tau_muon_mass_ratio",16.8167,0.0015,"")
const tau_neutron_mass_ratio = PhysicalConstant("tau_neutron_mass_ratio",1.89111,0.00017,"")
const tau_proton_mass_ratio = PhysicalConstant("tau_proton_mass_ratio",1.89372,0.00017,"")
const thomson_cross_section = PhysicalConstant("thomson_cross_section",0.6652458734e-28m^2,0.0000000013e-28m^2,"m^2")
const triton_electron_mass_ratio = PhysicalConstant("triton_electron_mass_ratio",5496.9215267,0.0000050,"")
const triton_g_factor = PhysicalConstant("triton_g_factor",5.957924896,0.000000076,"")
const triton_mag_mom = PhysicalConstant("triton_mag_mom",1.504609447e-26J*T^-1,0.000000038e-26J*T^-1,"J*T^-1")
const triton_mag_mom_to_bohr_magneton_ratio = PhysicalConstant("triton_mag_mom_to_bohr_magneton_ratio",1.622393657e-3,0.000000021e-3,"")
const triton_mag_mom_to_nuclear_magneton_ratio = PhysicalConstant("triton_mag_mom_to_nuclear_magneton_ratio",2.978962448,0.000000038,"")
const triton_mass = PhysicalConstant("triton_mass",5.00735630e-27kg,0.00000022e-27kg,"kg")
const triton_mass_energy_equivalent = PhysicalConstant("triton_mass_energy_equivalent",4.50038741e-10J,0.00000020e-10J,"J")
const triton_mass_energy_equivalent_in_mev = PhysicalConstant("triton_mass_energy_equivalent_in_mev",2808.921005MeV,0.000062MeV,"MeV")
const triton_mass_in_u = PhysicalConstant("triton_mass_in_u",3.0155007134u,0.0000000025u,"u")
const triton_molar_mass = PhysicalConstant("triton_molar_mass",3.0155007134e-3kg*mol^-1,0.0000000025e-3kg*mol^-1,"kg*mol^-1")
const triton_proton_mass_ratio = PhysicalConstant("triton_proton_mass_ratio",2.9937170308,0.0000000025,"")
const unified_atomic_mass_unit = PhysicalConstant("unified_atomic_mass_unit",1.660538921e-27kg,0.000000073e-27kg,"kg")
const von_klitzing_constant = PhysicalConstant("von_klitzing_constant",25812.8074434Ohm,0.0000084Ohm,"Ohm")
const weak_mixing_angle = PhysicalConstant("weak_mixing_angle",0.2223,0.0021,"")
const wien_frequency_displacement_law_constant = PhysicalConstant("wien_frequency_displacement_law_constant",5.8789254e10Hz*K^-1,0.0000053e10Hz*K^-1,"Hz*K^-1")
const wien_wavelength_displacement_law_constant = PhysicalConstant("wien_wavelength_displacement_law_constant",2.8977721e-3m*K,0.0000026e-3m*K,"m*K")
end # end of module definition


text:
@testset "Simplices" begin

# checks that to SimplexGraphs are identical up to a permutation of the simplices.
function simplexgraphcmp(sg1,sg2)
	@test size(sg1.G)==size(sg2.G)
	@test size(sg1.w)==size(sg2.w)
	N = size(sg1.G,2)
	if sg1.w isa AbstractVector
		perm1 = sortperm(1:N, by=i->(sg1.w[i], sg1.G[:,i]))
		perm2 = sortperm(1:N, by=i->(sg2.w[i], sg2.G[:,i]))
		@test sg1.w[perm1] == sg2.w[perm2]
	else
		perm1 = sortperm(1:N, by=i->sg1.G[:,i])
		perm2 = sortperm(1:N, by=i->sg2.G[:,i])
	end
	@test sg1.G[:,perm1] == sg2.G[:,perm2]
	nothing
end

@testset "ThreeGroups" begin
	sgAnswer = SimplexGraph(Bool[1 0 0; 1 0 0; 0 1 0; 0 0 1], [2,1,1])
	SAnswer = [2/3 1/3 0 0; 1/3 2/3 0 0; 0 0 1 0; 0 0 0 1]

	annot = ["A","A","B","C"]
	sg = groupsimplices(annot)
	simplexgraphcmp(sg,sgAnswer)
	S = simplices2kernelmatrix(sg)
	@test S ≈ SAnswer

	# try permuted version
	perm = [2, 3, 4, 1]
	sg = groupsimplices(annot[perm])
	simplexgraphcmp(sg, SimplexGraph(sgAnswer.G[perm,:],sgAnswer.w))
	S = simplices2kernelmatrix(sg)
	@test S ≈ SAnswer[perm,perm]
end

@testset "OneSample" begin
	annot = ["A"]
	sg = groupsimplices(annot)
	simplexgraphcmp(sg, SimplexGraph(trues(1,1),[1]))
	S = simplices2kernelmatrix(sg)
	@test S ≈ ones(1,1)
end

@testset "OneGroup" begin
	annot = ["A", "A", "A"]
	sg = groupsimplices(annot)
	simplexgraphcmp(sg, SimplexGraph(trues(3,1),[3]))
	S = simplices2kernelmatrix(sg)
	@test S ≈ (Diagonal(ones(3)) + ones(3,3))/4
end

@testset "UniqueGroups" begin
	annot = ["A", "B", "C", "D"]
	sg = groupsimplices(annot)
	simplexgraphcmp(sg, SimplexGraph(Diagonal(trues(4)),ones(Int,4)))
	S = simplices2kernelmatrix(sg)
	@test S ≈ Diagonal(ones(4))
end

@testset "OneTimeSeries" begin
	N = 6
	annot = repeat(["A"], N)
	t = 1:N
	sg = timeseriessimplices(t, groupby=annot)
	simplexgraphcmp(sg, SimplexGraph(SymTridiagonal(trues(N),trues(N-1)), ones(Int,N)))
	S = simplices2kernelmatrix(sg)
	@test S ≈ [1/2 1/4 1/12 0 0 0; 1/4 2/3 1/6 1/12 0 0; 1/12 1/6 1/2 1/6 1/12 0; 0 1/12 1/6 1/2 1/6 1/12; 0 0 1/12 1/6 2/3 1/4; 0 0 0 1/12 1/4 1/2]
end

@testset "TwoTimeSeries" begin
	N = 6
	annot = repeat(["A","B"], inner=N)
	t = repeat(1:N, 2)
	sg = timeseriessimplices(t, groupby=annot)
	T = SymTridiagonal(trues(N),trues(N-1))
	Z = falses(N,N)
	simplexgraphcmp(sg, SimplexGraph([T Z; Z T], ones(Int,2N)))
	S = simplices2kernelmatrix(sg)
	S1 = [1/2 1/4 1/12 0 0 0; 1/4 2/3 1/6 1/12 0 0; 1/12 1/6 1/2 1/6 1/12 0; 0 1/12 1/6 1/2 1/6 1/12; 0 0 1/12 1/6 2/3 1/4; 0 0 0 1/12 1/4 1/2]
	@test S ≈ [S1 Z; Z S1]
end

@testset "OneTimeSeries2" begin
	N = 6
	annot = repeat(["A"], 2N)
	t = div.(0:2N-1,2)
	sg = timeseriessimplices(t, groupby=annot)
	simplexgraphcmp(sg, SimplexGraph(repeat(SymTridiagonal(trues(N),trues(N-1)), inner=(2,1)), 2*ones(N)))
	S = simplices2kernelmatrix(sg)
	@test S ≈ [31/105 31/210 31/210 31/210 1/21 1/21 0 0 0 0 0 0; 31/210 31/105 31/210 31/210 1/21 1/21 0 0 0 0 0 0; 31/210 31/210 41/105 41/210 2/21 2/21 1/21 1/21 0 0 0 0; 31/210 31/210 41/210 41/105 2/21 2/21 1/21 1/21 0 0 0 0; 1/21 1/21 2/21 2/21 2/7 1/7 2/21 2/21 1/21 1/21 0 0; 1/21 1/21 2/21 2/21 1/7 2/7 2/21 2/21 1/21 1/21 0 0; 0 0 1/21 1/21 2/21 2/21 2/7 1/7 2/21 2/21 1/21 1/21; 0 0 1/21 1/21 2/21 2/21 1/7 2/7 2/21 2/21 1/21 1/21; 0 0 0 0 1/21 1/21 2/21 2/21 41/105 41/210 31/210 31/210; 0 0 0 0 1/21 1/21 2/21 2/21 41/210 41/105 31/210 31/210; 0 0 0 0 0 0 1/21 1/21 31/210 31/210 31/105 31/210; 0 0 0 0 0 0 1/21 1/21 31/210 31/210 31/210 31/105]
end

@testset "MixedTimeSeries" begin
	GAnswer = Bool[1 1 0 0 0 0 0 0 0 0; 1 1 1 0 0 0 0 0 0 0; 1 1 1 0 0 0 0 0 0 0; 0 1 1 0 0 0 0 0 0 0; 0 1 1 0 0 0 0 0 0 0; 0 1 1 0 0 0 0 0 0 0; 0 0 0 1 0 0 0 0 0 0; 0 0 0 0 1 0 0 0 0 0; 0 0 0 0 1 0 0 0 0 0; 0 0 0 0 1 0 0 0 0 0; 0 0 0 0 0 1 1 0 0 0; 0 0 0 0 0 1 1 0 0 0; 0 0 0 0 0 1 1 1 0 0; 0 0 0 0 0 0 1 1 1 0; 0 0 0 0 0 0 0 1 1 1; 0 0 0 0 0 0 0 1 1 1; 0 0 0 0 0 0 0 1 1 1; 0 0 0 0 0 0 0 0 1 1]
	wAnswer = Int[1, 2, 3, 1, 3, 2, 1, 1, 3, 1]
	SAnswer = [11/42 11/84 11/84 1/21 1/21 1/21 0 0 0 0 0 0 0 0 0 0 0 0; 11/84 97/210 97/420 31/210 31/210 31/210 0 0 0 0 0 0 0 0 0 0 0 0; 11/84 97/420 97/210 31/210 31/210 31/210 0 0 0 0 0 0 0 0 0 0 0 0; 1/21 31/210 31/210 31/105 31/210 31/210 0 0 0 0 0 0 0 0 0 0 0 0; 1/21 31/210 31/210 31/210 31/105 31/210 0 0 0 0 0 0 0 0 0 0 0 0; 1/21 31/210 31/210 31/210 31/210 31/105 0 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 1/1 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 1/2 1/4 1/4 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 1/4 1/2 1/4 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 1/4 1/4 1/2 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 13/30 13/60 13/60 1/20 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 13/60 13/30 13/60 1/20 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 13/60 13/60 1/2 1/12 1/30 1/30 1/30 0; 0 0 0 0 0 0 0 0 0 0 1/20 1/20 1/12 11/30 2/15 2/15 2/15 1/10; 0 0 0 0 0 0 0 0 0 0 0 0 1/30 2/15 11/30 11/60 11/60 3/20; 0 0 0 0 0 0 0 0 0 0 0 0 1/30 2/15 11/60 11/30 11/60 3/20; 0 0 0 0 0 0 0 0 0 0 0 0 1/30 2/15 11/60 11/60 11/30 3/20; 0 0 0 0 0 0 0 0 0 0 0 0 0 1/10 3/20 3/20 3/20 3/10]

	annot = ["A", "A", "A", "A", "A", "A", "B", "C", "C", "C", "D", "D", "D", "D", "D", "D", "D", "D" ]
	t     = [ 0,   5,   5,   7,   7,   7,   8,   4,   4,   8,   1,   1,   2,   3,   4,   4,   4,   5  ]
	sg = timeseriessimplices(t, groupby=annot)
	simplexgraphcmp(sg, SimplexGraph(GAnswer,wAnswer))
	S = simplices2kernelmatrix(sg)
	@test S ≈ SAnswer

	# try permuted version
	perm = [3, 9, 13, 12, 2, 4, 17, 10, 7, 14, 11, 1, 6, 8, 5, 15, 18, 16]
	sg = timeseriessimplices(t[perm], groupby=annot[perm])
	simplexgraphcmp(sg, SimplexGraph(GAnswer[perm,:],wAnswer))
	S = simplices2kernelmatrix(sg)
	@test S ≈ SAnswer[perm,perm]
end

@testset "kNN" begin
	A = Float64[9 1 3 9 3 3 7 3 5 5; 0 2 3.99 7 1 1 8 4 7.01 1; 0 6 3 7 0 9 0 2 0 6; 8 8 7 6 5 9 1 4 2 5];

	sg = neighborsimplices(A)
	@test sg.G == Diagonal(trues(10))
	S = simplices2kernelmatrix(sg)
	@test S ≈ Diagonal(ones(10))

	sg = neighborsimplices(A; k=1)
	@test sg.G == Bool[1 0 0 0 0 0 0 0 0 0; 0 1 0 0 0 1 0 0 0 0; 0 0 1 0 0 0 0 1 0 1; 0 0 0 1 0 0 0 0 0 0; 1 0 0 0 1 0 0 0 0 0; 0 1 0 0 0 1 0 0 0 0; 0 0 0 0 0 0 1 0 1 0; 0 0 1 0 1 0 0 1 0 0; 0 0 0 0 0 0 1 0 1 0; 0 0 0 1 0 0 0 0 0 1]
	S = simplices2kernelmatrix(sg)
	@test S ≈ [1/3 0 0 0 1/6 0 0 0 0 0; 0 2/3 0 0 0 1/3 0 0 0 0; 0 0 1 0 0 0 0 1/3 0 1/6; 0 0 0 1/3 0 0 0 0 0 1/6; 1/6 0 0 0 2/3 0 0 1/6 0 0; 0 1/3 0 0 0 2/3 0 0 0 0; 0 0 0 0 0 0 2/3 0 1/3 0; 0 0 1/3 0 1/6 0 0 1 0 0; 0 0 0 0 0 0 1/3 0 2/3 0; 0 0 1/6 1/6 0 0 0 0 0 2/3]

	sg = neighborsimplices(A; k=2)
	@test sg.G == Bool[1 0 0 0 0 0 0 0 0 0; 0 1 1 0 0 1 0 0 0 1; 1 1 1 1 1 0 0 1 0 1; 0 0 0 1 0 0 0 0 0 0; 1 0 0 0 1 0 0 1 0 0; 0 1 0 0 0 1 0 0 0 0; 0 0 0 0 0 0 1 0 1 0; 0 0 1 0 1 0 1 1 1 0; 0 0 0 0 0 0 1 0 1 0; 0 0 0 1 0 1 0 0 0 1]
	S = simplices2kernelmatrix(sg)
	@test S ≈ [1/6 0 1/12 0 1/12 0 0 0 0 0; 0 2/3 1/4 0 0 1/6 0 1/12 0 1/6; 1/12 1/4 7/6 1/12 1/4 1/12 0 1/4 0 1/6; 0 0 1/12 1/6 0 0 0 0 0 1/12; 1/12 0 1/4 0 1/2 0 0 1/6 0 0; 0 1/6 1/12 0 0 1/3 0 0 0 1/12; 0 0 0 0 0 0 1/3 1/6 1/6 0; 0 1/12 1/4 0 1/6 0 1/6 5/6 1/6 0; 0 0 0 0 0 0 1/6 1/6 1/3 0; 0 1/6 1/6 1/12 0 1/12 0 0 0 1/2]

	sg = neighborsimplices(A; k=6)
	@test sg.G == Bool[1 0 0 0 1 0 0 0 0 0; 0 1 1 0 1 1 0 1 0 1; 1 1 1 1 1 1 1 1 1 1; 1 1 0 1 0 1 1 0 1 1; 1 1 1 0 1 1 1 1 1 1; 0 1 1 1 0 1 0 0 0 1; 0 0 0 1 0 0 1 1 1 0; 1 1 1 1 1 1 1 1 1 1; 1 0 1 1 1 0 1 1 1 0; 1 1 1 1 1 1 1 1 1 1]
	S = simplices2kernelmatrix(sg)
	@test S ≈ [1/14 1/56 1/28 1/56 1/28 0 0 1/28 1/28 1/28; 1/56 3/14 3/28 3/56 3/28 1/14 1/56 3/28 3/56 3/28; 1/28 3/28 5/14 1/8 9/56 5/56 1/14 5/28 1/8 5/28; 1/56 3/56 1/8 1/4 3/28 1/14 3/56 1/8 1/14 1/8; 1/28 3/28 9/56 3/28 9/28 1/14 3/56 9/56 3/28 9/56; 0 1/14 5/56 1/14 1/14 5/28 1/56 5/56 1/28 5/56; 0 1/56 1/14 3/56 3/56 1/56 1/7 1/14 1/14 1/14; 1/28 3/28 5/28 1/8 9/56 5/56 1/14 5/14 1/8 5/28; 1/28 3/56 1/8 1/14 3/28 1/28 1/14 1/8 1/4 1/8; 1/28 3/28 5/28 1/8 9/56 5/56 1/14 5/28 1/8 5/14]

	sg = neighborsimplices(A; k=9)
	@test sg.G == trues(10,10)
	S = simplices2kernelmatrix(sg)
	@test S ≈ (ones(10,10)+Diagonal(ones(10)))/11
end

@testset "NNDist" begin
	A = Float64[9 1 0 4 0 9 0 8 7 2; 3 6 4 4 0 6 4 2 5 4; 0 7 7 7 8 7 6 5 0 2; 5 6 8 9 5 5 5 1 7 9]

	sg = neighborsimplices(A; r=0.05)
	@test sg.G == Diagonal(trues(10))
	S = simplices2kernelmatrix(sg)
	@test S ≈ Diagonal(ones(10))

	sg = neighborsimplices(A; r=0.225)
	@test sg.G == Bool[1 0 0 0 0 0 0 0 1 0; 0 1 1 1 0 0 1 0 0 0; 0 1 1 1 1 0 1 0 0 1; 0 1 1 1 0 0 1 0 0 1; 0 0 1 0 1 0 1 0 0 0; 0 0 0 0 0 1 0 1 0 0; 0 1 1 1 1 0 1 0 0 1; 0 0 0 0 0 1 0 1 0 0; 1 0 0 0 0 0 0 0 1 1; 0 0 1 1 0 0 1 0 1 1]
	S = simplices2kernelmatrix(sg)
	@test S ≈ [1/2 0 0 0 0 0 0 0 1/4 1/12; 0 11/42 11/84 11/84 1/21 0 11/84 0 0 17/210; 0 11/84 52/105 23/140 11/84 0 26/105 0 1/30 4/35; 0 11/84 23/140 23/70 1/21 0 23/140 0 1/30 4/35; 0 1/21 11/84 1/21 11/42 0 11/84 0 0 1/21; 0 0 0 0 0 2/3 0 1/3 0 0; 0 11/84 26/105 23/140 11/84 0 52/105 0 1/30 4/35; 0 0 0 0 0 1/3 0 2/3 0 0; 1/4 0 1/30 1/30 0 0 1/30 0 17/30 7/60; 1/12 17/210 4/35 4/35 1/21 0 4/35 0 7/60 83/210]

	sg = neighborsimplices(A; r=0.36)
	@test sg.G == Bool[1 0 0 1 0 1 0 1 1 1; 0 1 1 1 1 1 1 1 1 1; 0 1 1 1 1 1 1 0 0 1; 1 1 1 1 1 1 1 1 1 1; 0 1 1 1 1 0 1 1 0 1; 1 1 1 1 0 1 1 1 1 1; 0 1 1 1 1 1 1 1 1 1; 1 1 0 1 1 1 1 1 1 0; 1 1 0 1 0 1 1 1 1 1; 1 1 1 1 1 1 1 0 1 1]
	S = simplices2kernelmatrix(sg)
	@test S ≈ [383/2310 13/220 31/990 383/4620 3/88 383/4620 13/220 199/2772 383/4620 1913/27720; 13/220 811/3465 1237/13860 811/6930 2551/27720 2749/27720 811/6930 2441/27720 161/1980 953/9240; 31/990 1237/13860 1237/6930 1237/13860 361/4620 1979/27720 1237/13860 557/9240 53/990 1237/13860; 383/4620 811/6930 1237/13860 976/3465 2551/27720 487/3960 811/6930 443/3960 1457/13860 391/3080; 3/88 2551/27720 361/4620 2551/27720 2551/13860 257/3465 2551/27720 437/6930 223/3960 361/4620; 383/4620 2749/27720 1979/27720 487/3960 257/3465 487/1980 2749/27720 1303/13860 1457/13860 6/55; 13/220 811/6930 1237/13860 811/6930 2551/27720 2749/27720 811/3465 2441/27720 161/1980 953/9240; 199/2772 2441/27720 557/9240 443/3960 437/6930 1303/13860 2441/27720 443/1980 1303/13860 97/990; 383/4620 161/1980 53/990 1457/13860 223/3960 1457/13860 161/1980 1303/13860 1457/6930 281/3080; 1913/27720 953/9240 1237/13860 391/3080 361/4620 6/55 953/9240 97/990 281/3080 391/1540]

	sg = neighborsimplices(A; r=1.0)
	@test sg.G == trues(10,10)
	S = simplices2kernelmatrix(sg)
	@test S ≈ (Diagonal(ones(10)) + ones(10,10))/11
end

@testset "kNNDist" begin
	A = Float64[1 0 -9 0 0 -6 3 -3 -1 7; -1 0 -5 1 1 0 -6 0 0 -1; 0 -5 2 2 0.01 -1 -2 0 0 4; -4 -2 0 -7 -5 -4 0 0 -5 0.01]

	sg = neighborsimplices(A; k=2, r=0.28)
	@test sg.G == Bool[1 1 0 1 1 0 1 1 1 1; 1 1 0 0 0 0 1 0 0 0; 0 0 1 0 0 0 0 0 0 0; 1 0 0 1 1 0 0 0 1 0; 1 0 0 1 1 0 0 0 1 0; 0 0 1 0 0 1 0 1 1 0; 0 0 0 0 0 0 1 0 0 1; 1 0 1 0 0 1 0 1 1 0; 1 1 0 1 1 1 0 1 1 0; 0 0 0 0 0 0 0 0 0 1]
	S = simplices2kernelmatrix(sg)
	@test S ≈ [94/105 4/21 0 31/210 31/210 31/420 1/6 41/420 59/210 1/12; 4/21 8/21 0 1/42 1/42 0 1/12 1/42 3/28 0; 0 0 1/6 0 0 1/12 0 1/12 0 0; 31/210 1/42 0 31/105 31/210 1/42 0 1/21 31/210 0; 31/210 1/42 0 31/210 31/105 1/42 0 1/21 31/210 0; 31/420 0 1/12 1/42 1/42 101/210 0 101/420 11/70 0; 1/6 1/12 0 0 0 0 1/3 0 0 1/12; 41/420 1/42 1/12 1/21 1/21 101/420 0 37/70 19/105 0; 59/210 3/28 0 31/210 31/210 11/70 0 19/105 51/70 0; 1/12 0 0 0 0 0 1/12 0 0 1/6]
end

@testset "kNNDistReduced" begin
    A = Float64[76 48 40 14 -15 7 -42 -57 -37 -34; 84 23 59 76 22 -8 -123 -44 -77 -12; -56 -28 36 -59 37 50 -21 8 23 10; -19 -59 -84 42 50 22 -5 38 -19 34; 33 56 -9 -97 56 2 -2 -44 -19 24; 36 98 -13 32 19 25 -81 53 -50 -119]

    sg = neighborsimplices(A; k=2, r=0.32, dim=1)
    @test sg.G == Bool[1 1 1 1 0 0 0 0 0 0; 1 1 1 1 0 0 0 0 0 0; 1 1 1 1 1 1 0 1 0 0; 1 1 1 1 1 1 0 0 0 0; 0 0 1 1 1 1 0 1 0 0; 0 0 1 1 1 1 0 1 0 0; 0 0 0 0 0 0 1 0 1 1; 0 0 1 0 1 1 0 1 1 1; 0 0 0 0 0 0 1 1 1 1; 0 0 0 0 0 0 1 1 1 1]
    S = simplices2kernelmatrix(sg)
    @test S ≈ [17/60 17/120 17/120 17/120 1/24 1/24 0 1/56 0 0; 17/120 17/60 17/120 17/120 1/24 1/24 0 1/56 0 0; 17/120 17/120 13/28 5/24 37/280 37/280 0 13/120 1/42 1/42; 17/120 17/120 5/24 5/12 13/120 13/120 0 71/840 0 0; 1/24 1/24 37/280 13/120 37/140 37/280 0 13/120 1/42 1/42; 1/24 1/24 37/280 13/120 37/280 37/140 0 13/120 1/42 1/42; 0 0 0 0 0 0 11/30 1/10 11/60 11/60; 1/56 1/56 13/120 71/840 13/120 13/120 1/10 5/12 13/105 13/105; 0 0 1/42 0 1/42 1/42 11/60 13/105 29/70 29/140; 0 0 1/42 0 1/42 1/42 11/60 13/105 29/140 29/70]

    sg = neighborsimplices(A; k=2, r=0.42, dim=3)
    @test sg.G == Bool[1 1 1 1 0 0 0 0 0 0; 1 1 1 0 1 0 0 0 0 0; 1 1 1 0 1 1 0 0 0 0; 0 0 0 1 0 0 0 0 0 0; 0 1 1 0 1 1 0 1 1 0; 0 0 1 1 1 1 0 1 1 0; 0 0 0 0 0 0 1 0 1 1; 0 0 0 0 1 1 0 1 0 0; 0 0 0 0 1 1 1 0 1 1; 0 0 0 0 0 0 1 0 1 1]
    S = simplices2kernelmatrix(sg)
    @test S ≈ [1/2 1/6 1/6 1/12 1/12 7/60 0 0 0 0; 1/6 8/21 4/21 0 3/28 2/35 0 1/42 1/42 0; 1/6 4/21 47/105 0 59/420 19/210 0 2/35 2/35 0; 1/12 0 0 1/6 0 1/12 0 0 0 0; 1/12 3/28 59/420 0 18/35 29/140 1/30 59/420 19/210 1/30; 7/60 2/35 19/210 1/12 29/140 61/105 1/30 59/420 19/210 1/30; 0 0 0 0 1/30 1/30 2/5 0 1/5 1/5; 0 1/42 2/35 0 59/420 59/420 0 59/210 2/35 0; 0 1/42 2/35 0 19/210 19/210 1/5 2/35 18/35 1/5; 0 0 0 0 1/30 1/30 1/5 0 1/5 2/5]

    sg = neighborsimplices(A; k=2, r=0.45, dim=5)
    @test sg.G == Bool[1 1 1 1 0 0 0 0 0 0; 1 1 0 0 0 0 0 0 0 0; 1 0 1 0 0 1 0 0 0 0; 0 0 0 1 0 0 0 0 0 0; 0 0 0 0 1 1 0 1 0 0; 0 1 1 0 1 1 0 1 1 0; 0 0 0 0 0 0 1 0 1 1; 0 0 0 1 1 1 0 1 1 0; 0 0 0 0 0 1 1 1 1 1; 0 0 0 0 0 0 1 0 1 1]
    S = simplices2kernelmatrix(sg)
    @test S ≈ [2/3 1/6 1/6 1/12 0 1/6 0 1/12 0 0; 1/6 1/3 1/12 0 0 1/12 0 0 0 0; 1/6 1/12 2/5 0 1/30 7/60 0 1/30 1/30 0; 1/12 0 0 1/6 0 0 0 1/12 0 0; 0 0 1/30 0 1/3 1/6 0 1/6 1/12 0; 1/6 1/12 7/60 0 1/6 11/15 1/30 1/5 7/60 1/30; 0 0 0 0 0 1/30 2/5 1/30 1/5 1/5; 1/12 0 1/30 1/12 1/6 1/5 1/30 17/30 7/60 1/30; 0 0 1/30 0 1/12 7/60 1/5 7/60 17/30 1/5; 0 0 0 0 0 1/30 1/5 1/30 1/5 2/5]

    sg = neighborsimplices(A'; k=1, r=0.4, dim=1)
    @test sg.G == Bool[1 1 0 0 1 1; 1 1 0 0 0 1; 0 0 1 1 1 0; 0 0 1 1 1 0; 1 0 1 1 1 1; 1 1 0 0 1 1]
    S = simplices2kernelmatrix(sg)
    @test S ≈ [13/30 11/60 1/30 1/30 2/15 13/60; 11/60 11/30 0 0 1/10 11/60; 1/30 0 2/5 1/5 1/5 1/30; 1/30 0 1/5 2/5 1/5 1/30; 2/15 1/10 1/5 1/5 3/5 2/15; 13/60 11/60 1/30 1/30 2/15 13/30]

    sg = neighborsimplices(A'; k=1, r=0.45, dim=3)
    @test sg.G == Bool[1 1 1 0 1 1; 1 1 0 0 0 0; 1 0 1 1 1 0; 0 0 1 1 0 0; 1 0 1 0 1 0; 1 0 0 0 0 1]
    S = simplices2kernelmatrix(sg)
    @test S ≈ [1/1 1/5 1/6 1/20 1/6 1/5; 1/5 2/5 1/30 0 1/30 1/30; 1/6 1/30 2/3 13/60 1/6 1/30; 1/20 0 13/60 13/30 1/20 0; 1/6 1/30 1/6 1/20 1/3 1/30; 1/5 1/30 1/30 0 1/30 2/5]

    sg = neighborsimplices(A'; k=1, r=0.55, dim=5)
    @test sg.G == Bool[1 1 1 0 1 1; 1 1 0 0 0 1; 1 0 1 1 1 0; 0 0 1 1 1 0; 1 0 1 1 1 0; 1 1 0 0 0 1]
    S = simplices2kernelmatrix(sg)
    @test S ≈ [3/5 1/5 2/15 1/10 2/15 1/5; 1/5 2/5 1/30 0 1/30 1/5; 2/15 1/30 13/30 11/60 13/60 1/30; 1/10 0 11/60 11/30 11/60 0; 2/15 1/30 13/60 11/60 13/30 1/30; 1/5 1/5 1/30 0 1/30 2/5]
end

@testset "NNGrouped" begin
	A = Float64[76 48 40 14 -15 7 -42 -57 -37 -34; 84 23 59 76 22 -8 -123 -44 -77 -12; -56 -28 36 -59 37 50 -21 8 23 10; -19 -59 -84 42 50 22 -5 38 -19 34; 33 56 -9 -97 56 2 -2 -44 -19 24; 36 98 -13 32 19 25 -81 53 -50 -119]
	annot = ["A","B","A","A","B","A","A","B","C","B"]

	sg = neighborsimplices(A; k=1, groupby=annot)
	simplexgraphcmp(sg, SimplexGraph(Bool[1 0 0 1 0 0 0 0 0 0; 0 1 0 0 0 0 0 0 0 0; 1 0 1 0 0 1 0 0 0 0; 0 0 0 1 0 0 0 0 0 0; 0 1 0 0 1 0 0 1 0 1; 0 0 1 0 0 1 1 0 0 0; 0 0 0 0 0 0 1 0 0 0; 0 0 0 0 1 0 0 1 0 0; 0 0 0 0 0 0 0 0 1 0; 0 0 0 0 0 0 0 0 0 1]))

	sg = neighborsimplices(A; k=2, groupby=annot)
	simplexgraphcmp(sg, SimplexGraph(Bool[1 0 1 1 0 1 0 0 0 0; 0 1 0 0 0 0 0 0 0 0; 1 0 1 0 0 1 1 0 0 0; 1 0 0 1 0 0 0 0 0 0; 0 1 0 0 1 0 0 1 0 1; 0 0 1 1 0 1 1 0 0 0; 0 0 0 0 0 0 1 0 0 0; 0 1 0 0 1 0 0 1 0 1; 0 0 0 0 0 0 0 0 1 0; 0 0 0 0 1 0 0 1 0 1]))

	sg = neighborsimplices(A; k=4, groupby=annot)
	simplexgraphcmp(sg, SimplexGraph(Bool[1 0 1 1 0 1 1 0 0 0; 0 1 0 0 1 0 0 1 0 1; 1 0 1 1 0 1 1 0 0 0; 1 0 1 1 0 1 1 0 0 0; 0 1 0 0 1 0 0 1 0 1; 1 0 1 1 0 1 1 0 0 0; 1 0 1 1 0 1 1 0 0 0; 0 1 0 0 1 0 0 1 0 1; 0 0 0 0 0 0 0 0 1 0; 0 1 0 0 1 0 0 1 0 1]))

	sg = neighborsimplices(A; r=0.6, groupby=annot)
	simplexgraphcmp(sg, SimplexGraph(Bool[1 0 1 1 0 1 0 0 0 0; 0 1 0 0 1 0 0 0 0 0; 1 0 1 0 0 1 0 0 0 0; 1 0 0 1 0 1 0 0 0 0; 0 1 0 0 1 0 0 1 0 1; 1 0 1 1 0 1 1 0 0 0; 0 0 0 0 0 1 1 0 0 0; 0 0 0 0 1 0 0 1 0 0; 0 0 0 0 0 0 0 0 1 0; 0 0 0 0 1 0 0 0 0 1]))

	sg = neighborsimplices(A; r=2.0, groupby=annot)
	simplexgraphcmp(sg, SimplexGraph(Bool[1 0 1 1 0 1 1 0 0 0; 0 1 0 0 1 0 0 1 0 1; 1 0 1 1 0 1 1 0 0 0; 1 0 1 1 0 1 1 0 0 0; 0 1 0 0 1 0 0 1 0 1; 1 0 1 1 0 1 1 0 0 0; 1 0 1 1 0 1 1 0 0 0; 0 1 0 0 1 0 0 1 0 1; 0 0 0 0 0 0 0 0 1 0; 0 1 0 0 1 0 0 1 0 1]))
end

end

ext: jl


text:
using Documenter
using Metadata

makedocs(;
    modules=[Metadata],
    format=Documenter.HTML(),
    pages=[
        "Metadata" => "index.md",
   ],
    repo="https://github.com/Tokazama/Metadata.jl/blob/{commit}{path}#L{line}",
    sitename="Metadata.jl",
    authors="Zachary P. Christensen",
)

deploydocs(
    repo = "github.com/Tokazama/Metadata.jl.git",
)


text:
for n in [:IOBase, :RawIOBase, :BufferedIOBase, :TextIOBase]
    p = Symbol(:Py, n)
    t = Symbol(p, :_Type)
    tr = Symbol(p, :__ref)
    c = Symbol(p, :_Check)
    @eval const $tr = Ref(PyNULL)
    @eval $t(doimport::Bool = true) = begin
        ptr = $tr[]
        isnull(ptr) || return ptr
        a = doimport ? PyImport_ImportModule("io") : PyImport_GetModule("io")
        isnull(a) && return a
        b = PyObject_GetAttrString(a, $(string(n)))
        Py_DecRef(a)
        isnull(b) && return b
        $tr[] = b
    end
    @eval $c(o) = begin
        t = $t(false)
        isnull(t) && return (PyErr_IsSet() ? Cint(-1) : Cint(0))
        PyObject_IsInstance(o, t)
    end
end


text:
function ARC(; kwargs...)
  cur_dict = Dict{Symbol, AbstractFloat}(
    :N_G => 0.67,
    :kappa => 1.84,
    :epsilon => 0.342,
    :beta_N => 0.0259,
    :Q => 13.6,
    :f_D => 0.85,
    :eta_CD => 0.321,
    :P_F => 525,
    :B_max => 23,
    :b => 0.85,
    :nu_n => 0.385,
    :nu_T => 0.929,
    :nu_J => 0.472,
    :eta_T => 0.4
  )

  merge!(cur_dict, kwargs)

  Reactor(; cur_dict...)
end


text:
function arithmetic (a = parse(Int, readline()), b = parse(Int, readline()))
  for op in  [+,-,*,div,rem]
    println("a $op b = $(op(a,b))")
  end
end

max_stars_repo_name: ethansaxenian/RosettaDecode

max_issues_repo_name: ethansaxenian/RosettaDecode

max_forks_repo_name: ethansaxenian/RosettaDecode


text:
#
# Computes the total potential energy of the system
#

function utotal_parallel1(p,data)
    nthreads = Threads.nthreads()
    utotal = zeros(nthreads)
    Threads.@threads for ip in 1:data.N-1
        id = Threads.threadid()
        for jp in ip+1:data.N
            rij = rpbc(p[ip],p[jp],data.bdim)
            if rij < data.cutoff
                utotal[id] += upair(rij,data)
            end
        end
    end
    return sum(utotal)
end

function ij_pair(N)
    npairs = N*(N-1)÷2
    ij = Array{Int}(undef, npairs, 2)
    for ipair in 1:npairs
        ij[ipair,1], ij[ipair,2] = linear_index(ipair)
    end
    return ij
end
export ij_pair

function utotal_serial2(p,data,ij)
    @unpack N, bdim, cutoff = data
    npairs = N*(N-1)÷2
    utotal = 0.
    for ipair in 1:npairs
        ip = ij[ipair,1]
        jp = ij[ipair,2]
        rij = rpbc(p[ip],p[jp], bdim)
        if rij < cutoff
            utotal += upair(rij,data)
        end
    end
    return utotal
end

function utotal_parallel2(p,data,ij)
    nthreads = Threads.nthreads()
    @unpack N, bdim, cutoff = data
    npairs = N*(N-1)÷2
    utotal = zeros(nthreads)
    npthreads = npairs ÷ nthreads
    if mod(npairs, nthreads) != 0
        error(" mod(npairs, nthreads) != 0 ")
    end
    Threads.@threads for id = 1:nthreads
        ifirst = npthreads*(id - 1) + 1
        ilast = npthreads*id
        for ipair in ifirst:ilast
            ip = ij[ipair,1]
            jp = ij[ipair,2]
            rij = rpbc(p[ip],p[jp], bdim)
            if rij < cutoff
                utotal[id] += upair(rij,data)
            end
        end
    end
    return sum(utotal)
end


text:
# # Numerical Dynamic Programming

# Florian Oswald, Sciences Po, 2019

# ## Intro

# * Numerical Dynamic Programming (DP) is widely used to solve dynamic models.
# * You are familiar with the technique from your core macro course.
# * We will illustrate some ways to solve dynamic programs.
#     1. Models with one discrete or continuous choice variable
#     1. Models with several choice variables
#     1. Models with a discrete-continuous choice combination
# * We will go through:
#     1. Value Function Iteration (VFI)
#     1. Policy function iteration (PFI)
#     1. Projection Methods
#     1. Endogenous Grid Method (EGM)
#     1. Discrete Choice Endogenous Grid Method (DCEGM)

# ## Dynamic Programming Theory

# * Payoffs over time are
# 	$$U=\sum_{t=1}^{\infty}\beta^{t}u\left(s_{t},c_{t}\right) $$
# 	where $\beta<1$ is a discount factor, $s_{t}$ is the state, $c_{t}$ is the control.

# * The state (vector) evolves as $s_{t+1}=h(s_{t},c_{t})$.
# * All past decisions are contained in $s_{t}$.

# ### Assumptions

# * Let $c_{t}\in C(s_{t}),s_{t}\in S$ and assume $u$ is bounded in $(c,s)\in C\times S$.
# * Stationarity: neither payoff $u$ nor transition $h$ depend on time.
# * Write the problem as
# 	$$ v(s)=\max_{s'\in\Gamma(s)}u(s,s')+\beta v(s') $$
# * $\Gamma(s)$ is the constraint set (or feasible set) for $s'$ when the current state is $s$

# ### Existence

# **Theorem.** Assume that $u(s,s')$ is real-valued, continuous, and bounded, that $\beta\in(0,1)$, and that the constraint set $\Gamma(s)$ is nonempty, compact, and continuous. Then there exists a unique function $v(s)$ that solves the above functional equation.

# **Proof.** [@stokeylucas] <cite data-cite=stokeylucas></cite> theoreom 4.6.

# # Solution Methods

# ## Value Function Iteration (VFI)

# * Find the fix point of the functional equation by iterating on it until the distance between consecutive iterations becomes small.
# * Motivated by the Bellman Operator, and it's characterization in the Continuous Mapping Theorem.

# ## Discrete DP VFI

# * Represents and solves the functional problem in $\mathbb{R}$ on a finite set of grid points only.
# * Widely used method.
#    * Simple (+)
#    * Robust (+)
#    * Slow (-)
#    * Imprecise (-)
# * Precision depends on number of discretization points used.
# * High-dimensional problems are difficult to tackle with this method because of the curse of dimensionality.

# ### Deterministic growth model with Discrete VFI

# * We have this theoretical model:

# \begin{eqnarray}
#    V(k) &=& \max_{0<k'<f(k)} u(f(k) - k') + \beta V(k')\\
#   f(k)  &=& k^\alpha
# \end{eqnarray}

# * and we employ the followign numerical approximation:
# 	$$ V(k_i) = \max_{i'=1,2,\dots,n} u(f(k_i) - k_{i'}) + \beta V(i') $$

# * The iteration is then on successive iterates of $V$: The LHS gets updated in each iteration!

# $$
# \begin{aligned}
# 	V^{r+1}(k_i) &= \max_{i'=1,2,\dots,n} u(f(k_i) - k_{i'}) + \beta V^{r}(i') \\
# 	V^{r+2}(k_i) &= \max_{i'=1,2,\dots,n} u(f(k_i) - k_{i'}) + \beta V^{r+1}(i') \\
# 	... &
# \end{aligned}
# $$

# * And it stops at iteration $r$ if $d(V^{r},V^{r-1}) < \text{tol}$
# * You choose a measure of *distance*, $d(\cdot,\cdot)$, and a level of tolerance.
# * $V^{r}$ is usually an *array*. So $d$ will be some kind of *norm*.
# * maximal absolute distance
# * mean squared distance

# ### Exercise 1: Implement discrete VFI

# ## Checklist

# 1. Set parameter values
# 1. define a grid for state variable $k \in [0,2]$
# 1. initialize value function $V$
# 1. start iteration, repeatedly computing a new version of $V$.
# 1. stop if $d(V^{r},V^{r-1}) < \text{tol}$.
# 1. plot value and policy function
# 1. report the maximum error of both wrt to analytic solution

alpha     = 0.65
beta      = 0.95
grid_max  = 2  # upper bound of capital grid
n         = 150  # number of grid points
N_iter    = 3000  # number of iterations
kgrid     = 1e-2:(grid_max-1e-2)/(n-1):grid_max  # equispaced grid
f(x) = x^alpha  # defines the production function f(k)
tol = 1e-9


text:
function build_gram_matrix(q::Vector{MOI.VariableIndex},
                           monos::AbstractVector{<:MP.AbstractMonomial})
    return build_gram_matrix([MOI.SingleVariable(vi) for vi in q], monos)
end
function build_gram_matrix(q::Vector,
                           monos::AbstractVector{<:MP.AbstractMonomial})
    return GramMatrix(MultivariateMoments.SymMatrix(q, length(monos)),
                         monos)
end

function add_gram_matrix(model::MOI.ModelLike, matrix_cone_type::Type,
                         monos::AbstractVector{<:MP.AbstractMonomial})
    Q, cQ = MOI.add_constrained_variables(model, matrix_cone(matrix_cone_type, length(monos)))
    q = build_gram_matrix(Q, monos)
    return q, Q, cQ
end

function build_moment_matrix(q::Vector,
                             monos::AbstractVector{<:MP.AbstractMonomial})
    return MomentMatrix(MultivariateMoments.SymMatrix(q, length(monos)),
                        monos)
end

struct SOSPolynomialSet{DT <: AbstractSemialgebraicSet,
                        MT <: MP.AbstractMonomial,
                        MVT <: AbstractVector{MT},
                        CT <: Certificate.AbstractCertificate} <: MOI.AbstractVectorSet
    domain::DT
    monomials::MVT
    certificate::CT
end
MOI.dimension(set::SOSPolynomialSet) = length(set.monomials)


text:
import GreyDecision.Utility: makeminmax
import GreyDecision.GreyNumbers: GreyNumber
import GreyDecision.Vikor: vikor

@testset "Grey Vikor with real numbers" begin
    tol = 0.0001
    w =  [0.110, 0.035, 0.379, 0.384, 0.002, 0.002, 0.010, 0.077]
    #Amat = [
    #  100 92 10 2 80 70 95 80 ;
    #  80  70 8  4 100 80 80 90 ;
    #  90 85 5 0 75 95 70 70 ;
    #  70 88 20 18 60 90 95 85
    #]
    Amat = [
    GreyNumber{Float64}(100.0, 100.0) GreyNumber{Float64}(92.0, 92.0) GreyNumber{Float64}(10.0, 10.0) GreyNumber{Float64}(2.0, 2.0) GreyNumber{Float64}(80.0, 80.0) GreyNumber{Float64}(70.0, 70.0) GreyNumber{Float64}(95.0, 95.0) GreyNumber{Float64}(80.0, 80.0);
    GreyNumber{Float64}(80.0, 80.0) GreyNumber{Float64}(70.0, 70.0) GreyNumber{Float64}(8.0, 8.0) GreyNumber{Float64}(4.0, 4.0) GreyNumber{Float64}(100.0, 100.0) GreyNumber{Float64}(80.0, 80.0) GreyNumber{Float64}(80.0, 80.0) GreyNumber{Float64}(90.0, 90.0);
    GreyNumber{Float64}(90.0, 90.0) GreyNumber{Float64}(85.0, 85.0) GreyNumber{Float64}(5.0, 5.0) GreyNumber{Float64}(0.0, 0.0) GreyNumber{Float64}(75.0, 75.0) GreyNumber{Float64}(95.0, 95.0) GreyNumber{Float64}(70.0, 70.0) GreyNumber{Float64}(70.0, 70.0);
    GreyNumber{Float64}(70.0, 70.0) GreyNumber{Float64}(88.0, 88.0) GreyNumber{Float64}(20.0, 20.0) GreyNumber{Float64}(18.0, 18.0) GreyNumber{Float64}(60.0, 60.0) GreyNumber{Float64}(90.0, 90.0) GreyNumber{Float64}(95.0, 95.0) GreyNumber{Float64}(85.0, 85.0)
    ]

    fns = makeminmax([maximum, maximum, maximum, maximum, maximum, maximum, maximum, maximum])

    vikorresult = vikor(Amat, w, fns)

    @test vikorresult[:bestindex] == 4

    @test isapprox(vikorresult[:scores][1], GreyNumber(0.1975012087551764, 0.1975012087551764), atol=tol)
    @test isapprox(vikorresult[:scores][2], GreyNumber(0.2194064473270817, 0.2194064473270817), atol=tol)
    @test isapprox(vikorresult[:scores][3], GreyNumber(0.3507643203516215, 0.3507643203516215), atol=tol)
    @test isapprox(vikorresult[:scores][4], GreyNumber(-0.16727341435277993, -0.16727341435277993), atol=tol)

end


text:
struct InlineDisplay <: AbstractDisplay end

function sendDisplayMsg(kind, data)
    JSONRPC.send_notification(conn_endpoint[], "display", Dict{String,String}("kind" => kind, "data" => data))
end

function display(d::InlineDisplay, ::MIME{Symbol("image/png")}, x)
    payload = stringmime(MIME("image/png"), x)
    sendDisplayMsg("image/png", payload)
end

displayable(d::InlineDisplay, ::MIME{Symbol("image/png")}) = true

function display(d::InlineDisplay, ::MIME{Symbol("image/gif")}, x)
    payload = stringmime(MIME("image/gif"), x)
    sendDisplayMsg("image/gif", payload)
end

displayable(d::InlineDisplay, ::MIME{Symbol("image/gif")}) = true

function display(d::InlineDisplay, ::MIME{Symbol("image/svg+xml")}, x)
    payload = stringmime(MIME("image/svg+xml"), x)
    sendDisplayMsg("image/svg+xml", payload)
end

displayable(d::InlineDisplay, ::MIME{Symbol("image/svg+xml")}) = true

function display(d::InlineDisplay, ::MIME{Symbol("text/html")}, x)
    payload = stringmime(MIME("text/html"), x)
    sendDisplayMsg("text/html", payload)
end

displayable(d::InlineDisplay, ::MIME{Symbol("text/html")}) = true

function display(d::InlineDisplay, ::MIME{Symbol("juliavscode/html")}, x)
    payload = stringmime(MIME("juliavscode/html"), x)
    sendDisplayMsg("juliavscode/html", payload)
end

Base.Multimedia.istextmime(::MIME{Symbol("juliavscode/html")}) = true

displayable(d::InlineDisplay, ::MIME{Symbol("juliavscode/html")}) = true

function display(d::InlineDisplay, ::MIME{Symbol("application/vnd.vegalite.v2+json")}, x)
    payload = stringmime(MIME("application/vnd.vegalite.v2+json"), x)
    sendDisplayMsg("application/vnd.vegalite.v2+json", payload)
end

displayable(d::InlineDisplay, ::MIME{Symbol("application/vnd.vegalite.v2+json")}) = true

function display(d::InlineDisplay, ::MIME{Symbol("application/vnd.vegalite.v3+json")}, x)
    payload = stringmime(MIME("application/vnd.vegalite.v3+json"), x)
    sendDisplayMsg("application/vnd.vegalite.v3+json", payload)
end

displayable(d::InlineDisplay, ::MIME{Symbol("application/vnd.vegalite.v3+json")}) = true

function display(d::InlineDisplay, ::MIME{Symbol("application/vnd.vegalite.v4+json")}, x)
    payload = stringmime(MIME("application/vnd.vegalite.v4+json"), x)
    sendDisplayMsg("application/vnd.vegalite.v4+json", payload)
end

displayable(d::InlineDisplay, ::MIME{Symbol("application/vnd.vegalite.v4+json")}) = true

function display(d::InlineDisplay, ::MIME{Symbol("application/vnd.vega.v3+json")}, x)
    payload = stringmime(MIME("application/vnd.vega.v3+json"), x)
    sendDisplayMsg("application/vnd.vega.v3+json", payload)
end

displayable(d::InlineDisplay, ::MIME{Symbol("application/vnd.vega.v3+json")}) = true

function display(d::InlineDisplay, ::MIME{Symbol("application/vnd.vega.v4+json")}, x)
    payload = stringmime(MIME("application/vnd.vega.v4+json"), x)
    sendDisplayMsg("application/vnd.vega.v4+json", payload)
end

displayable(d::InlineDisplay, ::MIME{Symbol("application/vnd.vega.v4+json")}) = true

function display(d::InlineDisplay, ::MIME{Symbol("application/vnd.vega.v5+json")}, x)
    payload = stringmime(MIME("application/vnd.vega.v5+json"), x)
    sendDisplayMsg("application/vnd.vega.v5+json", payload)
end

displayable(d::InlineDisplay, ::MIME{Symbol("application/vnd.vega.v5+json")}) = true

function display(d::InlineDisplay, ::MIME{Symbol("application/vnd.plotly.v1+json")}, x)
    payload = stringmime(MIME("application/vnd.plotly.v1+json"), x)
    sendDisplayMsg("application/vnd.plotly.v1+json", payload)
end

displayable(d::InlineDisplay, ::MIME{Symbol("application/vnd.dataresource+json")}) = true

function display(d::InlineDisplay, ::MIME{Symbol("application/vnd.dataresource+json")}, x)
    payload = stringmime(MIME("application/vnd.dataresource+json"), x)
    sendDisplayMsg("application/vnd.dataresource+json", payload)
end

Base.Multimedia.istextmime(::MIME{Symbol("application/vnd.dataresource+json")}) = true

displayable(d::InlineDisplay, ::MIME{Symbol("application/vnd.plotly.v1+json")}) = true

const DISPLAYABLE_MIMES = [
    "application/vnd.vegalite.v4+json",
    "application/vnd.vegalite.v3+json",
    "application/vnd.vegalite.v2+json",
    "application/vnd.vega.v5+json",
    "application/vnd.vega.v4+json",
    "application/vnd.vega.v3+json",
    "application/vnd.plotly.v1+json",
    "juliavscode/html",
    # "text/html",
    "image/svg+xml",
    "image/png",
    "image/gif"
]

function can_display(x)
    for mime in DISPLAYABLE_MIMES
        if showable(mime, x)
            return true
        end
    end

    if showable("application/vnd.dataresource+json", x)
        return true
    end

    istable = Base.invokelatest(_isiterabletable, x)

    if istable === missing || istable === true || x isa AbstractVector || x isa AbstractMatrix
        return true
    end

    return false
end

function Base.display(d::InlineDisplay, x)
    for mime in DISPLAYABLE_MIMES
        if showable(mime, x)
            return display(d, mime, x)
        end
    end

    throw(MethodError(display, (d, x)))
end

function _display(d::InlineDisplay, x)
    if showable("application/vnd.dataresource+json", x)
        display(d, "application/vnd.dataresource+json", x)
    else
        try
            display(d, x)
        catch err
            if err isa MethodError
                @warn "Cannot display values of type $(typeof(x)) in VS Code."
            else
                rethrow(err)
            end
        end
    end
end

const tabletraits_uuid = UUIDs.UUID("3783bdb8-4a98-5b6b-af9a-565f29a5fe9c")
const datavalues_uuid = UUIDs.UUID("e7dc6d0d-1eca-5fa6-8ad6-5aecde8b7ea5")

global _isiterabletable = i->false
global _getiterator = i->i

function pkgload(pkg)
    if pkg.uuid == tabletraits_uuid
        x = Base.require(pkg)

        global _isiterabletable = x.isiterabletable
        global _getiterator = x.getiterator
    elseif pkg.uuid == datavalues_uuid
        x = Base.require(pkg)

        eval(
            quote
            function JSON_print_escaped(io, val::$(x.DataValue))
                $(x.isna)(val) ? print(io, "null") : JSON_print_escaped(io, val[])
            end

            julia_type_to_schema_type(::Type{T}) where {S,T <: $(x.DataValue){S}} = julia_type_to_schema_type(S)
        end
        )
    end
end

function repl_showingrid_notification(conn, params::String)
    try
        var = Base.invokelatest(Base.include_string, Main, params)

        Base.invokelatest(internal_vscodedisplay, var)
    catch err
        Base.display_error(err, catch_backtrace())
    end
end

function internal_vscodedisplay(x)
    if showable("application/vnd.dataresource+json", x)
        _display(InlineDisplay(), x)
    elseif _isiterabletable(x) === true
        buffer = IOBuffer()
        io = IOContext(buffer, :compact => true)
        printdataresource(io, _getiterator(x))
        buffer_asstring = CachedDataResourceString(String(take!(buffer)))
        _display(InlineDisplay(), buffer_asstring)
    elseif _isiterabletable(x) === missing
        try
            buffer = IOBuffer()
            io = IOContext(buffer, :compact => true)
            printdataresource(io, _getiterator(x))
            buffer_asstring = CachedDataResourceString(String(take!(buffer)))
            _display(InlineDisplay(), buffer_asstring)
        catch err
            _display(InlineDisplay(), x)
        end
    elseif x isa AbstractVector || x isa AbstractMatrix
        buffer = IOBuffer()
        io = IOContext(buffer, :compact => true)
        print_array_as_dataresource(io, _getiterator(x))
        buffer_asstring = CachedDataResourceString(String(take!(buffer)))
        _display(InlineDisplay(), buffer_asstring)
    else
        _display(InlineDisplay(), x)
    end
end

vscodedisplay(x) = internal_vscodedisplay(x)
vscodedisplay() = i->vscodedisplay(i)

max_stars_repo_name: Cvikli/julia-vscode

max_issues_repo_name: Cvikli/julia-vscode

max_forks_repo_name: Cvikli/julia-vscode


text:
using Pkg
using LinearAlgebra
using DataFrames
using Printf
using Random

println("test corr-pf")

# load functions
include(pwd()*"/src/SDEMEM OU process/ou_sdemem.jl")
include(pwd()*"/src/SDEMEM OU process/mcmc.jl")

N_time = 200
M_subjects = 40
nbr_particles_cor = 50

y,x,t_vec,dt,η,σ_ϵ,ϕ,prior_parameters_η,prior_parameters_σ_ϵ = set_up(M=M_subjects,N=N_time,seed=500)

#σ_ϵ = 0.31

# estimate correlation
nbr_pf_eval_corr = 100

ll1 = zeros(nbr_pf_eval_corr)
ll2 = zeros(nbr_pf_eval_corr)

ρ = 0.999
corr_ll_vec = zeros(25)

Random.seed!(1)

for j in 1:25

    for i = 1:nbr_pf_eval_corr

        u_prop_old_block_1 = randn(nbr_particles_cor,N_time + 1,M_subjects)
        u_resample_old_block_1 = randn(N_time,2,M_subjects)

        u_prop_new = randn(nbr_particles_cor,N_time + 1,M_subjects)
        u_resample_new = randn(N_time,2,M_subjects)

        # correlat with old standard normal numbers
        u_prop_tilde = ρ*u_prop_old_block_1 + sqrt(1-ρ^2)*u_prop_new
        u_resample_tilde = ρ*u_resample_old_block_1 + sqrt(1-ρ^2)*u_resample_new

        ll1[i] = sum(cpf(y, σ_ϵ, ϕ, dt, u_prop_old_block_1, u_resample_old_block_1, nbr_particles_cor,true))
        ll2[i] = sum(cpf(y, σ_ϵ, ϕ, dt, u_prop_tilde, u_resample_tilde, nbr_particles_cor,true))

    end

    corr_ll_vec[j] = cor(ll1,ll2)

end

corr_ll = mean(corr_ll_vec)

var_loglik_target = 2.16^2/(1-corr_ll^2)

#nbr_pf_eval = 100
#nbr_particles = 50

function loglik_est(nbr_particles, nbr_pf_eval=100)

    ll = zeros(nbr_pf_eval)
    for i = 1:nbr_pf_eval
        println(i)

        ll[i] = sum(cpf(y, σ_ϵ, ϕ, dt, randn(nbr_particles,N_time + 1,M_subjects), randn(N_time,2,M_subjects), nbr_particles, true))
    end

    return ll

end

nbr_pf_eval = 10000
nbr_particles = [5,10,15,20] #,50,100,500]

loglik_matrix = zeros(nbr_pf_eval, length(nbr_particles))
run_times = zeros(length(nbr_particles))

run_times[1]  = @elapsed loglik_matrix[:,1] = loglik_est(nbr_particles[1], nbr_pf_eval)

for i in 1:length(nbr_particles)
    @printf "Current nbr of particels: %.2f\n" nbr_particles[i]
    run_times[i]  = @elapsed loglik_matrix[:,i]  = loglik_est(nbr_particles[i], nbr_pf_eval)
end

mean_vals = mean(loglik_matrix, dims = 1)
println(mean_vals)

quantile_vals = zeros(2, length(nbr_particles))

for i in 1:length(nbr_particles)
    quantile_vals[:,i] = quantile(loglik_matrix[:,i], [0.1, 0.9])
end

using PyPlot

s_1 = """10th and 90th
         quantile"""

PyPlot.figure(figsize=(25,15))
PyPlot.plot(nbr_particles, mean_vals', "-*", color = "k", label = "Mean")
PyPlot.plot(nbr_particles, quantile_vals[1,:], "--*", color = "k", label = s_1)
PyPlot.plot(nbr_particles, quantile_vals[2,:], "--*", color = "k") #label = "90th quantile")
PyPlot.xticks(fontsize=16)
PyPlot.yticks(fontsize=16)
PyPlot.xlabel("Nbr particles.", fontsize=16)
PyPlot.ylabel("Loglik est.", fontsize=16)
PyPlot.legend(loc="upper left", bbox_to_anchor=(1, 0.5), fontsize=16)
display(gcf())
PyPlot.savefig("figures/avg_loglik_val_bootstap_ou.png")

print(quantile_vals[1,:])
print(mean_vals)
print(quantile_vals[2,:])

PyPlot.figure(figsize=(20,10))
PyPlot.plot(nbr_particles, mean(loglik_matrix, dims = 1)[:], "--*")
PyPlot.xlabel("Nbr particles.")
PyPlot.ylabel("Avg. loglik est. val.")
display(gcf())
PyPlot.savefig("figures/avg_loglik_val_vs_nbr_particels_cpf_099.png")

PyPlot.figure(figsize=(20,10))
PyPlot.plot(nbr_particles, var(loglik_matrix, dims = 1)[:], "--*")
PyPlot.plot(nbr_particles, var_loglik_target*ones(length(nbr_particles),1), "k")
PyPlot.xlabel("Nbr particles.")
PyPlot.ylabel("Var of loglik est.")
display(gcf())

#PyPlot.savefig("figures/loglik_var_vs_nbr_particles_cpf_099.png")

PyPlot.figure(figsize=(20,10))
PyPlot.plot(nbr_particles, run_times/100, "--*")
PyPlot.xlabel("Nbr particles.")
PyPlot.ylabel("Run time (sec)")
display(gcf())

#PyPlot.savefig("figures/run_time_vs_nbr_particls_cpf_099.png")


text:
#Write a program that asks the user for a number n and prints the sum of the numbers 1 to n

println("Please provide a integer to sum")
num = parse(Int64,readline())

function n_sum(x::Int64)
    sum(1:x)
end

println(n_sum(num))

max_stars_repo_name: atott/Simple-Programming-Problems-Julia

max_issues_repo_name: atott/Simple-Programming-Problems-Julia

max_forks_repo_name: atott/Simple-Programming-Problems-Julia