Add files
This commit is contained in:
146
core/include/bertini2/system/start/mhom.hpp
Normal file
146
core/include/bertini2/system/start/mhom.hpp
Normal file
@@ -0,0 +1,146 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//mhom.hpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//mhom.hpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with mhom.hpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2015 - 2021 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
// Tim Hodges, Colorado State University
|
||||
// silviana amethyst, university of wisconsin eau claire
|
||||
|
||||
/**
|
||||
\file mhom.hpp
|
||||
|
||||
\brief Defines the MHomogeneous start system type.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "bertini2/system/start_base.hpp"
|
||||
#include "bertini2/system/start/utility.hpp"
|
||||
|
||||
namespace bertini
|
||||
{
|
||||
namespace start_system
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
\brief The $m$-homogeneous start system for Numerical Algebraic Geometry
|
||||
|
||||
|
||||
*/
|
||||
class MHomogeneous : public StartSystem
|
||||
{
|
||||
public:
|
||||
MHomogeneous() = default;
|
||||
virtual ~MHomogeneous() = default;
|
||||
|
||||
/**
|
||||
Constructor for making a multi-homogeneous start system from a polynomial system
|
||||
|
||||
\throws std::runtime_error, if the input target system is not square, is not polynomial, has a path variable already.
|
||||
|
||||
Constructor can take in a non-homogeneous system or homogeneous system.
|
||||
*/
|
||||
MHomogeneous(System const& s);
|
||||
|
||||
/**
|
||||
\brief Creates a degree matrix for constructing the multi-homogeneous start system.
|
||||
*/
|
||||
void CreateDegreeMatrix(System const& s);
|
||||
|
||||
/**
|
||||
\brief Creates all valid partitions for multi-homogeneous start system to create start points.
|
||||
*/
|
||||
void GenerateValidPartitions(System const& s);
|
||||
|
||||
/**
|
||||
\brief Helper function that is used to find valid partitions in the degree matrix.
|
||||
*/
|
||||
int ChooseColumnInRow(System const& s,Vec<int>& variable_group_counter, int row, int column);
|
||||
|
||||
/**
|
||||
Get the number of start points for this m-homogeneous start system. This is the Bezout bound for the target system. Provided here for your convenience.
|
||||
*/
|
||||
unsigned long long NumStartPoints() const override;
|
||||
|
||||
unsigned long long NumStartPointsForPartition(Vec<int> partition) const;
|
||||
|
||||
MHomogeneous& operator*=(Nd const& n);
|
||||
|
||||
MHomogeneous& operator+=(System const& sys) = delete;
|
||||
|
||||
/**
|
||||
\brief Degree matrix holding degrees for all functions in terms of all variable groups
|
||||
*/
|
||||
Mat<int> degree_matrix_; // stores degrees of all functions in all homogeneous variable groups.
|
||||
|
||||
/**
|
||||
\brief Partitions used for creating start points in the multi-homogeneous start system.
|
||||
*/
|
||||
std::deque< Vec<int> > valid_partitions_;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
Get the ith start point, in double precision.
|
||||
|
||||
Called by the base StartSystem's StartPoint(index) method.
|
||||
*/
|
||||
Vec<dbl> GenerateStartPoint(dbl,unsigned long long index) const override;
|
||||
|
||||
/**
|
||||
Get the ith start point, in current default precision.
|
||||
|
||||
Called by the base StartSystem's StartPoint(index) method.
|
||||
*/
|
||||
Vec<mpfr_complex> GenerateStartPoint(mpfr_complex,unsigned long long index) const override;
|
||||
|
||||
/**
|
||||
A local version of GenerateStartPoint that can be templated
|
||||
*/
|
||||
template<typename T>
|
||||
void GenerateStartPointT(Vec<T>& start_point, unsigned long long index) const;
|
||||
|
||||
|
||||
|
||||
|
||||
std::vector<unsigned long long> degrees_; ///< stores the degrees of the functions.
|
||||
std::vector< VariableGroup > var_groups_;
|
||||
Mat<std::shared_ptr<node::LinearProduct>> linprod_matrix_; ///< All the linear products for each entry in the degree matrix.
|
||||
std::vector< std::vector<size_t> > variable_cols_; ///< The columns associated with each variable. The first index is the variable group, the second index is the particular variable in the group.
|
||||
|
||||
mutable Vec<mpfr_complex> temp_v_mp_;
|
||||
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template <typename Archive>
|
||||
void serialize(Archive& ar, const unsigned version)
|
||||
{
|
||||
ar & boost::serialization::base_object<StartSystem>(*this);
|
||||
ar & degrees_;
|
||||
}
|
||||
|
||||
};
|
||||
}//end start_system namespace
|
||||
}//end bertini namespace
|
||||
|
||||
|
||||
|
||||
148
core/include/bertini2/system/start/total_degree.hpp
Normal file
148
core/include/bertini2/system/start/total_degree.hpp
Normal file
@@ -0,0 +1,148 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//total_degree.hpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//total_degree.hpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with total_degree.hpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2015 - 2021 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
// silviana amethyst, university of wisconsin eau claire
|
||||
|
||||
/**
|
||||
\file total_degree.hpp
|
||||
|
||||
\brief Defines the TotalDegree start system type.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "bertini2/system/start_base.hpp"
|
||||
#include "bertini2/system/start/utility.hpp"
|
||||
|
||||
namespace bertini
|
||||
{
|
||||
namespace start_system{
|
||||
|
||||
|
||||
/**
|
||||
\brief Total degree start system for 1-homogeneous polynomial systems.
|
||||
|
||||
The most basic and easy-to-construct start system in Numerical Algebraic Geometry.
|
||||
|
||||
The total degree start system uses functions of the form \f$x_i^{d_i} - r_i\f$, where \f$i\f$ is the index of the function relative to the system, \f$d_i\f$ is the degree of that function, and \f$r_i\f$ is a random complex number. This is very similar to the roots of unity, except that they are moved away from being centered around the origin, to being centered around a random complex number.
|
||||
|
||||
Note that the corresponding target system MUST be square -- have the same number of functions and variables. The start system cannot be constructed otherwise, particularly because it is written to throw at the moment if not square.
|
||||
|
||||
The start points are accesses by index (unsigned long long), instead of being generated all at once.
|
||||
*/
|
||||
class TotalDegree : public StartSystem
|
||||
{
|
||||
public:
|
||||
TotalDegree() = default;
|
||||
virtual ~TotalDegree() = default;
|
||||
|
||||
/**
|
||||
Constructor for making a total degree start system from a polynomial system
|
||||
|
||||
\throws std::runtime_error, if the input target system is not square, is not polynomial, has a path variable already, has more than one variable group, or has any homogeneous variable groups.
|
||||
*/
|
||||
TotalDegree(System const& s);
|
||||
|
||||
|
||||
/**
|
||||
Get the random value for start function with index
|
||||
|
||||
\param index The index of the start function for which you want the corresponding random value.
|
||||
*/
|
||||
template<typename NumT>
|
||||
NumT RandomValue(size_t index) const
|
||||
{
|
||||
return random_values_[index]->Eval<NumT>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Get all the random values, in their Node form.
|
||||
*/
|
||||
std::vector<std::shared_ptr<node::Rational> > const& RandomValues()
|
||||
{
|
||||
return random_values_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Get the number of start points for this total degree start system. This is the Bezout bound for the target system. Provided here for your convenience.
|
||||
*/
|
||||
unsigned long long NumStartPoints() const override;
|
||||
|
||||
TotalDegree& operator*=(Nd const& n);
|
||||
|
||||
TotalDegree& operator+=(System const& sys) = delete;
|
||||
|
||||
void SanityChecks(System const& s);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
Copy the degrees from another system into this one
|
||||
*/
|
||||
void CopyDegrees(System const& s);
|
||||
|
||||
/**
|
||||
Populate the random values of this system.
|
||||
*/
|
||||
void SeedRandomValues(int num_functions);
|
||||
|
||||
/**
|
||||
Generate the functions for this total degree start system. Assumes the random values, degrees, and variables are already g2g.
|
||||
*/
|
||||
void GenerateFunctions();
|
||||
|
||||
|
||||
/**
|
||||
Get the ith start point, in double precision.
|
||||
|
||||
Called by the base StartSystem's StartPoint(index) method.
|
||||
*/
|
||||
Vec<dbl> GenerateStartPoint(dbl,unsigned long long index) const override;
|
||||
|
||||
/**
|
||||
Get the ith start point, in current default precision.
|
||||
|
||||
Called by the base StartSystem's StartPoint(index) method.
|
||||
*/
|
||||
Vec<mpfr_complex> GenerateStartPoint(mpfr_complex,unsigned long long index) const override;
|
||||
|
||||
std::vector<std::shared_ptr<node::Rational> > random_values_; ///< stores the random values for the start functions. x^d-r, where r is stored in this vector.
|
||||
std::vector<unsigned long long> degrees_; ///< stores the degrees of the functions.
|
||||
|
||||
|
||||
friend class boost::serialization::access;
|
||||
|
||||
template <typename Archive>
|
||||
void serialize(Archive& ar, const unsigned version) {
|
||||
ar & boost::serialization::base_object<StartSystem>(*this);
|
||||
ar & random_values_;
|
||||
ar & degrees_;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
157
core/include/bertini2/system/start/user.hpp
Normal file
157
core/include/bertini2/system/start/user.hpp
Normal file
@@ -0,0 +1,157 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//bertini2/system/start/user.hpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//bertini2/system/start/user.hpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with bertini2/system/start/user.hpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2015 - 2021 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
// silviana amethyst, university of wisconsin eau claire
|
||||
|
||||
/**
|
||||
\file bertini2/system/start/user.hpp
|
||||
|
||||
\brief Defines the User-defined start system type.
|
||||
|
||||
the user provided start system is merely their system, evaluated at the start time.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "bertini2/system/start_base.hpp"
|
||||
#include "bertini2/system/start/utility.hpp"
|
||||
#include "bertini2/common/config.hpp"
|
||||
|
||||
// these next two blobs solve a problem of private-ness.
|
||||
// see https://stackoverflow.com/questions/4112075/trouble-overriding-save-construct-data-when-serializing-a-pointer-to-a-class-wit
|
||||
|
||||
// forward declare the User start system
|
||||
namespace bertini{ namespace start_system{
|
||||
class User;
|
||||
}}
|
||||
|
||||
// forward declare the function, so we can friend it below.
|
||||
namespace boost { namespace serialization {
|
||||
template<class Archive>
|
||||
inline void save_construct_data(Archive & ar, const bertini::start_system::User * t, const unsigned int file_version);
|
||||
}}
|
||||
// end nonsense for friends. so lonely, but c++ friends don't solve the irl problem at all.
|
||||
|
||||
namespace bertini
|
||||
{
|
||||
namespace start_system{
|
||||
|
||||
|
||||
/**
|
||||
\brief The user-provided start system for Numerical Algebraic Geometry
|
||||
|
||||
|
||||
*/
|
||||
class User : public StartSystem
|
||||
{
|
||||
public:
|
||||
User() = delete; // deleted because requires a reference to a System to construct
|
||||
virtual ~User() = default;
|
||||
|
||||
/**
|
||||
Constructor for making a user-provided start system from another.
|
||||
*/
|
||||
User(System const& s, SampCont<dbl> const& solns);
|
||||
User(System const& s, SampCont<mpfr_complex> const& solns);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Get the number of start points for this start system.
|
||||
*/
|
||||
unsigned long long NumStartPoints() const override;
|
||||
|
||||
User& operator*=(Nd const& n) = delete;
|
||||
|
||||
User& operator+=(System const& sys) = delete;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
Get the ith start point, in double precision.
|
||||
|
||||
Called by the base StartSystem's StartPoint(index) method.
|
||||
*/
|
||||
Vec<dbl> GenerateStartPoint(dbl,unsigned long long index) const override;
|
||||
|
||||
/**
|
||||
Get the ith start point, in current default precision.
|
||||
|
||||
Called by the base StartSystem's StartPoint(index) method.
|
||||
*/
|
||||
Vec<mpfr_complex> GenerateStartPoint(mpfr_complex,unsigned long long index) const override;
|
||||
|
||||
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive> friend void boost::serialization::save_construct_data(Archive & ar, const User * t, const unsigned int file_version);
|
||||
|
||||
template <typename Archive>
|
||||
void serialize(Archive& ar, const unsigned version) {
|
||||
ar & boost::serialization::base_object<StartSystem>(*this);
|
||||
}
|
||||
|
||||
const bertini::System& user_system_;
|
||||
std::tuple<SampCont<dbl>, SampCont<mpfr_complex>> solns_;
|
||||
bool solns_in_dbl_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace boost { namespace serialization {
|
||||
template<class Archive>
|
||||
inline void save_construct_data(
|
||||
Archive & ar, const bertini::start_system::User * t, const unsigned int file_version
|
||||
){
|
||||
// save data required to construct instance
|
||||
ar << t->user_system_;
|
||||
ar << t->solns_in_dbl_;
|
||||
|
||||
ar << std::get<0>(t->solns_);
|
||||
ar << std::get<1>(t->solns_);
|
||||
|
||||
}
|
||||
|
||||
template<class Archive>
|
||||
inline void load_construct_data(
|
||||
Archive & ar, bertini::start_system::User * t, const unsigned int file_version
|
||||
){
|
||||
// retrieve data from archive required to construct new instance
|
||||
bertini::System sys;
|
||||
ar >> sys;
|
||||
|
||||
bool solns_in_dbl;
|
||||
ar >> solns_in_dbl;
|
||||
|
||||
if (solns_in_dbl)
|
||||
{
|
||||
bertini::SampCont<bertini::dbl> solns;
|
||||
ar >> solns;
|
||||
::new(t)bertini::start_system::User(sys, solns);
|
||||
}
|
||||
else
|
||||
{
|
||||
bertini::SampCont<bertini::mpfr_complex> solns;
|
||||
ar >> solns;
|
||||
::new(t)bertini::start_system::User(sys, solns);
|
||||
}
|
||||
}
|
||||
}}
|
||||
94
core/include/bertini2/system/start/utility.hpp
Normal file
94
core/include/bertini2/system/start/utility.hpp
Normal file
@@ -0,0 +1,94 @@
|
||||
//This file is part of Bertini 2.
|
||||
//
|
||||
//bertini2/system/start/utility.hpp is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//bertini2/system/start/utility.hpp is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with bertini2/system/start/utility.hpp. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// Copyright(C) 2015 - 2021 by Bertini2 Development Team
|
||||
//
|
||||
// See <http://www.gnu.org/licenses/> for a copy of the license,
|
||||
// as well as COPYING. Bertini2 is provided with permitted
|
||||
// additional terms in the b2/licenses/ directory.
|
||||
|
||||
// individual authors of this file include:
|
||||
// silviana amethyst, university of wisconsin - eau claire
|
||||
|
||||
/**
|
||||
\file bertini2/system/start/utility.hpp
|
||||
|
||||
\brief utilities for start system code.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BERTINI_START_SYSTEM_UTILITIES_HPP
|
||||
#define BERTINI_START_SYSTEM_UTILITIES_HPP
|
||||
|
||||
|
||||
|
||||
namespace bertini{
|
||||
|
||||
|
||||
/**
|
||||
\brief Convert a zero-based index to a zero-based subscript vector.
|
||||
|
||||
Throws `std::out_of_range` if the index is out-of-range based on the dimensions.
|
||||
|
||||
This goes from front to back, top to bottom. So
|
||||
|
||||
[0 2 4 [(0,0) (0,1) (0,2)
|
||||
1 3 5] (1,0) (1,1) (1,2)]
|
||||
|
||||
etc for higher-dimensional arrays. The functionality here is identical to that of Matlab's analagous call.
|
||||
|
||||
\param index The index you want to convert.
|
||||
\param dimensions The dimensions of the object you are subscripting or indexing into.
|
||||
\return A vector containing the subscripts for the input index.
|
||||
\throws std::out_of_range, if the index is impossible to convert.
|
||||
*/
|
||||
template <typename T>
|
||||
std::vector<T> IndexToSubscript(T index, std::vector<T> const& dimensions)
|
||||
{
|
||||
|
||||
std::vector< T > subscripts(dimensions.size());//for forming a subscript from an index
|
||||
|
||||
std::vector<T> k(dimensions.size(),1);
|
||||
for (int ii = 0; ii < dimensions.size()-1; ++ii)
|
||||
k[ii+1] = k[ii]*dimensions[ii];
|
||||
|
||||
|
||||
if (index >= k.back()*dimensions.back())
|
||||
throw std::out_of_range("in IndexToSubscript, index exceeds max based on dimension sizes");
|
||||
|
||||
|
||||
for (int ii = dimensions.size()-1; ii >= 0; --ii)
|
||||
{
|
||||
T I = index%k[ii];
|
||||
T J = (index - I) / k[ii];
|
||||
subscripts[ii] = J;
|
||||
index = I;
|
||||
}
|
||||
|
||||
return subscripts;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // re: namespace bertini
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user