Skip to content

Commit

Permalink
Simplifying ASA digama function and adding R_INTERUPTs
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Glaus committed Oct 9, 2013
1 parent aad5d6d commit c277c9a
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 119 deletions.
9 changes: 3 additions & 6 deletions Makefile
Expand Up @@ -57,8 +57,8 @@ estimateExpression: estimateExpression.cpp $(COMMON_DEPS) CollapsedSampler.o Gib
estimateHyperPar: estimateHyperPar.cpp $(COMMON_DEPS) lowess.o PosteriorSamples.o TranscriptExpression.o
$(CXX) $(CXXFLAGS) $(BOOSTFLAGS) $(LDFLAGS) estimateHyperPar.cpp $(COMMON_DEPS) lowess.o PosteriorSamples.o TranscriptExpression.o -o estimateHyperPar

estimateVBExpression: estimateVBExpression.cpp asa103/asa103.o $(COMMON_DEPS) SimpleSparse.o TagAlignments.o TranscriptInfo.o transposeFiles.o VariationalBayes.o
$(CXX) $(CXXFLAGS) $(BOOSTFLAGS) $(OPENMP) $(LDFLAGS) estimateVBExpression.cpp asa103/asa103.o $(COMMON_DEPS) SimpleSparse.o TagAlignments.o TranscriptInfo.o transposeFiles.o VariationalBayes.o -o estimateVBExpression
estimateVBExpression: estimateVBExpression.cpp $(COMMON_DEPS) SimpleSparse.o TagAlignments.o TranscriptInfo.o transposeFiles.o VariationalBayes.o
$(CXX) $(CXXFLAGS) $(BOOSTFLAGS) $(OPENMP) $(LDFLAGS) estimateVBExpression.cpp $(COMMON_DEPS) SimpleSparse.o TagAlignments.o TranscriptInfo.o transposeFiles.o VariationalBayes.o -o estimateVBExpression

extractSamples: extractSamples.cpp $(COMMON_DEPS) PosteriorSamples.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) extractSamples.cpp $(COMMON_DEPS) PosteriorSamples.o -o extractSamples
Expand Down Expand Up @@ -128,9 +128,6 @@ TranscriptSequence.o: TranscriptSequence.cpp TranscriptSequence.h
transposeFiles.o: transposeFiles.cpp transposeFiles.h FileHeader.h

# EXTERNAL LIBRARIES:
asa103/asa103.o:
make --directory asa103

samtools/sam.o:
make --directory samtools

Expand All @@ -139,4 +136,4 @@ clean:
rm *.o $(PROGRAMS)

clean-all:
rm samtools/*.o asa103/*.o *.o $(PROGRAMS)
rm samtools/*.o *.o $(PROGRAMS)
2 changes: 2 additions & 0 deletions VariationalBayes.cpp
Expand Up @@ -295,6 +295,7 @@ void VariationalBayes::optimize(bool verbose,OPT_TYPE method,long maxIter,double
squareNormOld=squareNorm;
boundOld=bound;
// }}}
R_INTERUPT;
}
if(quiet){
messageF("iter(%c): %5.ld bound: %.3lf grad: %.7lf beta: %.7lf\n",(usedSteepest?'s':'o'),iteration,bound,squareNorm,valBeta);
Expand Down Expand Up @@ -372,6 +373,7 @@ void VariationalBayes::generateSamples(long samplesN, const string &outTypeS, co
(*outF)<<gamma[m] * norm<<" ";
}
(*outF)<<endl;
R_INTERUPT;
}
// Delete lengths.
delete isoformLengths;
Expand Down
9 changes: 3 additions & 6 deletions _release_Makefile
Expand Up @@ -42,8 +42,8 @@ estimateExpression: estimateExpression.cpp $(COMMON_DEPS) CollapsedSampler.o Gib
estimateHyperPar: estimateHyperPar.cpp $(COMMON_DEPS) lowess.o PosteriorSamples.o TranscriptExpression.o
$(CXX) $(CXXFLAGS) $(BOOSTFLAGS) $(LDFLAGS) estimateHyperPar.cpp $(COMMON_DEPS) lowess.o PosteriorSamples.o TranscriptExpression.o -o estimateHyperPar

estimateVBExpression: estimateVBExpression.cpp asa103/asa103.o $(COMMON_DEPS) SimpleSparse.o TagAlignments.o TranscriptInfo.o transposeFiles.o VariationalBayes.o
$(CXX) $(CXXFLAGS) $(BOOSTFLAGS) $(OPENMP) $(LDFLAGS) estimateVBExpression.cpp asa103/asa103.o $(COMMON_DEPS) SimpleSparse.o TagAlignments.o TranscriptInfo.o transposeFiles.o VariationalBayes.o -o estimateVBExpression
estimateVBExpression: estimateVBExpression.cpp $(COMMON_DEPS) SimpleSparse.o TagAlignments.o TranscriptInfo.o transposeFiles.o VariationalBayes.o
$(CXX) $(CXXFLAGS) $(BOOSTFLAGS) $(OPENMP) $(LDFLAGS) estimateVBExpression.cpp $(COMMON_DEPS) SimpleSparse.o TagAlignments.o TranscriptInfo.o transposeFiles.o VariationalBayes.o -o estimateVBExpression

extractSamples: extractSamples.cpp $(COMMON_DEPS) PosteriorSamples.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) extractSamples.cpp $(COMMON_DEPS) PosteriorSamples.o -o extractSamples
Expand Down Expand Up @@ -113,13 +113,10 @@ TranscriptSequence.o: TranscriptSequence.cpp TranscriptSequence.h
transposeFiles.o: transposeFiles.cpp transposeFiles.h FileHeader.h

# EXTERNAL LIBRARIES:
asa103/asa103.o:
make --directory asa103

samtools/sam.o:
make --directory samtools

# CLEAN:
clean:
rm asa103/*.o samtools/*.o *.o $(PROGRAMS)
rm samtools/*.o *.o $(PROGRAMS)

6 changes: 0 additions & 6 deletions asa103/Makefile

This file was deleted.

100 changes: 0 additions & 100 deletions asa103/asa103.cpp

This file was deleted.

96 changes: 95 additions & 1 deletion asa103/asa103.hpp
@@ -1,2 +1,96 @@
double digama ( double x, int *ifault );
# include <cmath>

//****************************************************************************80

double digama ( double x, int *ifault )

//****************************************************************************80
//
// Purpose:
//
// DIGAMA calculates DIGAMMA ( X ) = d ( LOG ( GAMMA ( X ) ) ) / dX
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 18 January 2008
//
// Author:
//
// Original FORTRAN77 version by Jose Bernardo.
// C++ version by John Burkardt.
//
// Reference:
//
// Jose Bernardo,
// Algorithm AS 103:
// Psi ( Digamma ) Function,
// Applied Statistics,
// Volume 25, Number 3, 1976, pages 315-317.
//
// Parameters:
//
// Input, double X, the argument of the digamma function.
// 0 < X.
//
// Output, int *IFAULT, error flag.
// 0, no error.
// 1, X <= 0.
//
// Output, double DIGAMA, the value of the digamma function at X.
//
{
double c = 8.5;
double d1 = -0.5772156649;
double r;
double s = 0.00001;
double s3 = 0.08333333333;
double s4 = 0.0083333333333;
double s5 = 0.003968253968;
double value;
double y;
//
// Check the input.
//
if ( x <= 0.0 )
{
value = 0.0;
*ifault = 1;
return value;
}
//
// Initialize.
//
*ifault = 0;
y = x;
value = 0.0;
//
// Use approximation if argument <= S.
//
if ( y <= s )
{
value = d1 - 1.0 / y;
return value;
}
//
// Reduce to DIGAMA(X + N) where (X + N) >= C.
//
while ( y < c )
{
value = value - 1.0 / y;
y = y + 1.0;
}
//
// Use Stirling's (actually de Moivre's) expansion if argument > C.
//
r = 1.0 / y;
value = value + log ( y ) - 0.5 * r;
r = r * r;
value = value - r * ( s3 - r * ( s4 - r * s5 ) );

return value;
}
//****************************************************************************80

0 comments on commit c277c9a

Please sign in to comment.