Changeset 286af5f for src/unittests


Ignore:
Timestamp:
Dec 4, 2010, 11:56:28 PM (14 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
1fb318
Parents:
7d059d
git-author:
Frederik Heber <heber@…> (11/22/10 18:00:17)
git-committer:
Frederik Heber <heber@…> (12/04/10 23:56:28)
Message:

SubspaceFactorizerUnittest::SubspaceTest() - fully working compared to EigenvectorTest().

  • we also have an iteration and the results are exactly the same for a 3x3 matrix at run 2 and 9.
  • classes Eigenspace and Subspace are thus for now fully working.
Location:
src/unittests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/SubspaceFactorizerUnittest.cpp

    r7d059d r286af5f  
    356356  size_t run=1; // counting iterations
    357357  double threshold = 1.;  // containing threshold value
    358   while ((threshold > 1e-10) && (run < 2)) {
     358  while ((threshold > 1e-10) && (run < 10)) {
    359359    // for every dimension
    360     for (size_t dim = 0; dim<4;++dim) {
     360    for (size_t dim = 0; dim<subspacelimit;++dim) {
    361361      // for every index set of this dimension
    362362      Log() << Verbose(0) << std::endl << std::endl;
     
    491491    CurrentEigenvalues.push_back(0.);
    492492  }
    493   FullSpace.setEigenpairs(CurrentEigenvectors, CurrentEigenvalues);
    494493
    495494  Log() << Verbose(1) << "Generating sub spaces ..." << std::endl;
     
    526525  }
    527526
     527  size_t run=1; // counting iterations
     528  double threshold = 1.;  // containing threshold value
     529  while ((threshold > 1e-10) && (run < 10)) {
     530    // for every dimension
     531    for (size_t dim = 0; dim< subspacelimit;++dim) {
     532      // for every index set of this dimension
     533      Log() << Verbose(0) << std::endl << std::endl;
     534      Log() << Verbose(0) << "Current dimension is " << dim << std::endl;
     535      std::pair<SubspaceMap::const_iterator,SubspaceMap::const_iterator> Bounds = Dimension_to_Indexset.equal_range(dim);
     536      for (SubspaceMap::const_iterator IndexsetIter = Bounds.first;
     537          IndexsetIter != Bounds.second;
     538          ++IndexsetIter) {
     539        Subspace& subspace = *(IndexsetIter->second);
     540        // show the index set
     541        Log() << Verbose(0) << std::endl;
     542        Log() << Verbose(1) << "Current subspace is " << subspace << std::endl;
     543
     544        // solve
     545        subspace.calculateEigenSubspace();
     546
     547        // note that assignment to global eigenvectors all remains within subspace
     548      }
     549    }
     550
     551    // print list of similar eigenvectors
     552    BOOST_FOREACH( size_t index, AllIndices) {
     553      Log() << Verbose(2) << "Similar to " << index << "th current eigenvector " << *(CurrentEigenvectors[index]) << " are:" << std::endl;
     554      BOOST_FOREACH( SubspaceMap::value_type iter, Dimension_to_Indexset) {
     555        const VectorContent & CurrentEV = (iter.second)->getEigenvectorParallelToFullOne(index);
     556        if (!CurrentEV.IsZero())
     557          Log() << Verbose(2) << CurrentEV << std::endl;
     558      }
     559      Log() << Verbose(2) << std::endl;
     560    }
     561
     562    // create new CurrentEigenvectors from averaging parallel ones.
     563    BOOST_FOREACH(size_t index, AllIndices) {
     564      CurrentEigenvectors[index]->setZero();
     565      CurrentEigenvalues[index] = 0.;
     566      size_t count = 0;
     567      BOOST_FOREACH( SubspaceMap::value_type iter, Dimension_to_Indexset) {
     568        const VectorContent CurrentEV = (iter.second)->getEigenvectorParallelToFullOne(index);
     569        *CurrentEigenvectors[index] += CurrentEV * (iter.second)->getEigenvalueOfEigenvectorParallelToFullOne(index);
     570        CurrentEigenvalues[index] += (iter.second)->getEigenvalueOfEigenvectorParallelToFullOne(index);
     571        if (!CurrentEV.IsZero())
     572          count++;
     573      }
     574      *CurrentEigenvectors[index] *= 1./CurrentEigenvalues[index];
     575      CurrentEigenvalues[index] /= (double)count;
     576    }
     577
     578    // check orthonormality
     579    threshold = calculateOrthogonalityThreshold(AllIndices, CurrentEigenvectors);
     580    bool dontOrthonormalization = checkOrthogonality(AllIndices, CurrentEigenvectors);
     581
     582    // orthonormalize
     583    if (!dontOrthonormalization) {
     584      Log() << Verbose(0) << "Orthonormalizing ... " << std::endl;
     585      for (IndexSet::const_iterator firstindex = AllIndices.begin();
     586          firstindex != AllIndices.end();
     587          ++firstindex) {
     588        for (IndexSet::const_iterator secondindex = firstindex;
     589            secondindex != AllIndices.end();
     590            ++secondindex) {
     591          if (*firstindex == *secondindex) {
     592            (*CurrentEigenvectors[*secondindex]) *= 1./(*CurrentEigenvectors[*secondindex]).Norm();
     593          } else {
     594            (*CurrentEigenvectors[*secondindex]) -=
     595                ((*CurrentEigenvectors[*firstindex])*(*CurrentEigenvectors[*secondindex]))
     596                *(*CurrentEigenvectors[*firstindex]);
     597          }
     598        }
     599      }
     600    }
     601
     602//    // check orthonormality again
     603//    checkOrthogonality(AllIndices, CurrentEigenvectors);
     604
     605    // put obtained eigenvectors into full space
     606    FullSpace.setEigenpairs(CurrentEigenvectors, CurrentEigenvalues);
     607
     608    // show new ones
     609    Log() << Verbose(0) << "Resulting new eigenvectors and -values, run " << run << " are:" << std::endl;
     610    BOOST_FOREACH( size_t index, AllIndices) {
     611      Log() << Verbose(0) << *CurrentEigenvectors[index] << " with " << CurrentEigenvalues[index] << std::endl;
     612    }
     613    run++;
     614  }
     615
     616
    528617  CPPUNIT_ASSERT_EQUAL(0,0);
    529618}
  • src/unittests/SubspaceFactorizerUnittest.hpp

    r7d059d r286af5f  
    4040
    4141  enum { matrixdimension = 3 };
     42  enum { subspacelimit = 2 };
    4243private:
    4344
Note: See TracChangeset for help on using the changeset viewer.