|
Commons Math example source code file (README.txt)
The Commons Math README.txt source code
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#------------------------------------------------------------------------------
INTRODUCTION
The purpose of the R programs included in this directory is to validate
the target values used in Apache commons math unit tests. Success running the
R and commons-math tests on a platform (OS and R version) means that R and
commons-math give results for the test cases that are close in value. The
tests include configurable tolerance levels; but care must be taken in changing
these, since in most cases the pre-set tolerance is close to the number of
decimal digits used in expressing the expected values (both here and in the
corresponding commons-math unit tests).
Of course it is always possible that both R and commons-math give incorrect
values for test cases, so these tests should not be interpreted as definitive
in any absolute sense. The value of developing and running the tests is really
to generate questions (and answers!) when the two systems give different
results.
Contributions of additional test cases (both R and Junit code) or just
R programs to validate commons-math tests that are not covered here would be
greatly appreciated.
SETUP
0) Download and install R. You can get R here
http://www.r-project.org/
Follow the install instructions and make sure that you can launch R from this
(i.e., either explitly add R to your OS path or let the install package do it
for you).
1) Launch R from this directory and type
> source("testAll")
to an R prompt. This should produce output to the console similar to this:
Binomial test cases
Density test n = 10, p = 0.7...........................................SUCCEEDED
Distribution test n = 10, p = 0.7......................................SUCCEEDED
Inverse Distribution test n = 10, p = 0.7..............................SUCCEEDED
Density test n = 5, p = 0..............................................SUCCEEDED
Distribution test n = 5, p = 0.........................................SUCCEEDED
Density test n = 5, p = 1..............................................SUCCEEDED
Distribution test n = 5, p = 1.........................................SUCCEEDED
--------------------------------------------------------------------------------
Normal test cases
Distribution test mu = 2.1, sigma = 1.4................................SUCCEEDED
Distribution test mu = 2.1, sigma = 1.4................................SUCCEEDED
Distribution test mu = 0, sigma = 1....................................SUCCEEDED
Distribution test mu = 0, sigma = 0.1..................................SUCCEEDED
--------------------------------------------------------------------------------
...
<more test reports>
WORKING WITH THE TESTS
The R distribution comes with online manuals that you can view by launching
a browser instance and then entering
> help.start()
at an R prompt. Poking about in the test case files and the online docs should
bring you up to speed fairly quickly. Here are some basic things to get
you started. I should note at this point that I am by no means an expert R
programmer, so some things may not be implemented in the the nicest way.
Comments / suggestions for improvement are welcome!
All of the test cases use some basic functions and global constants (screen
width and success / failure strings) defined in "testFunctions." The
R "source" function is used to "import" these functions into each of the test
programs. The "testAll" program pulls together and executes all of the
individual test programs. You can execute any one of them by just entering
> source(<program-name>).
The "assertEquals" function in the testFunctions file mimics the similarly
named function used by Junit:
assertEquals <- function(expected, observed, tol, message) {
if(any(abs(expected - observed) > tol)) {
cat("FAILURE: ",message,"\n")
cat("EXPECTED: ",expected,"\n")
cat("OBSERVED: ",observed,"\n")
return(0)
} else {
return(1)
}
}
The <expected> and
Other Commons Math examples (source code examples)Here is a short list of links related to this Commons Math README.txt source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.