initializeErrorHandler¶
Initializes the PyIMSL error handling system.
Synopsis¶
initializeErrorHandler ()
Return Value¶
If the initialization succeeds, zero is returned. If there is an error, a nonzero value is returned.
Description¶
This function is used to initialize the PyIMSL error handling system for the current thread. It is not required, but is always allowed.
Use of this function is advised if the possibility of low heap memory exists
when calling PyIMSL for the first time in the current thread. A successful
return from initializeErrorHandler
confirms that the PyIMSL error
handling system has been initialized and is operational. The effects of
calling initializeErrorHandler
are limited to the calling thread only.
If initializeErrorHandler
is not called and initialization of the error
handling system fails, an error message is printed to stderr
, and
execution is stopped.
Example¶
In this example, the PyIMSL error handler is initialized prior to calling multiple other PyIMSL functions. Often this is not required, but is advised if the possibility of low heap memory exists. Even if not required, the initialization call is always allowed.
The computations performed in this example are based on Example 1 for regressionPrediction.
from __future__ import print_function
from numpy import *
from pyimsl.stat.regression import regression
from pyimsl.stat.regressionPrediction import regressionPrediction
from pyimsl.stat.initializeErrorHandler import initializeErrorHandler
from pyimsl.stat.writeMatrix import writeMatrix
x = array([
[7.0, 26.0, 6.0, 60.0],
[1.0, 29.0, 15.0, 52.0],
[11.0, 56.0, 8.0, 20.0],
[11.0, 31.0, 8.0, 47.0],
[7.0, 52.0, 6.0, 33.0],
[11.0, 55.0, 9.0, 22.0],
[3.0, 71.0, 17.0, 6.0],
[1.0, 31.0, 22.0, 44.0],
[2.0, 54.0, 18.0, 22.0],
[21.0, 47.0, 4.0, 26.0],
[1.0, 40.0, 23.0, 34.0],
[11.0, 66.0, 9.0, 12.0],
[10.0, 68.0, 8.0, 12.0]])
y = array([78.5, 74.3, 104.3, 87.6, 95.9, 109.2,
102.7, 72.5, 93.1, 115.9, 83.8, 113.3, 109.4])
# Initialize the IMSL C Stat Library error handler.
status = initializeErrorHandler()
# Verify successful error handler initialization before
# continuing.
if status == 0:
regression_info = []
# Fit the regression model
coefficients = regression(x, y, regressionInfo=regression_info)
regression_info = regression_info[0]
# Generate case statistics
y_hat = regressionPrediction(regression_info, x)
# Print results
writeMatrix("Predicted Responses", y_hat)
else:
print("Unable to initialize IMSL C Stat Library error handler.")
Output¶
Predicted Responses
1 2 3 4 5 6
78.5 72.8 106.0 89.3 95.6 105.3
7 8 9 10 11 12
104.1 75.7 91.7 115.6 81.8 112.3
13
111.7