Skip to content
This repository has been archived by the owner on Mar 1, 2021. It is now read-only.

Commit

Permalink
Added load/save to example 01
Browse files Browse the repository at this point in the history
  • Loading branch information
samcoveney committed Sep 25, 2017
1 parent 6ea741b commit 76322b0
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions examples/01_Emulator_Fit/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
help="sets the initial value of the nugget")
parser.add_argument("--fitnoise", default=False,
help="nugget will be trained on the data", action="store_true")
parser.add_argument("--load", default=False,
help="attempt to load emulator from .pkl file", action="store_true")
args = parser.parse_args()


Expand Down Expand Up @@ -71,18 +73,25 @@
y = y + args.noise*np.random.randn(y.size)
np.savetxt(OUTPUTS, y)


print("... Fitting an emulator")
## setup the emulator
## emulator instance
E = mp.Emulator()
E.Data.setup(INPUTS, OUTPUTS)
E.Basis.setup()
E.GP.setup(nugget = args.nugget, fixNugget = (not args.fitnoise))

## optimize the emulator
mp.optimize(E, tries=10)
if args.load == False:
## setup the emulator
E.Data.setup(INPUTS, OUTPUTS)
E.Basis.setup()
E.GP.setup(nugget = args.nugget, fixNugget = (not args.fitnoise))

## optimize the emulator
print("... Fitting an emulator")
mp.optimize(E, tries=10)

## save the emulator
E.save("emulator.pkl")
else:
## load the emulator
E.load("emulator.pkl")

## convert nugget into noise estimate
if args.fitnoise:
if E.GP.fixNugget == False:
noisesig = np.sqrt(E.GP.sigma**2 * (E.GP.nugget)/(1.0-E.GP.nugget))
print("... Noise width, as estimated from fitted sigma and nugget, is:" , noisesig)

0 comments on commit 76322b0

Please sign in to comment.