Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
change cleansq ratio, improve bump.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsofcotton authored Feb 21, 2024
1 parent 9cff0ca commit 7f8a82a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 16 deletions.
82 changes: 68 additions & 14 deletions lieonn.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ public:
if(entity[i] != other.entity[i]) return true;
return false;
}
inline T dot (const SimpleVector<T>& other) const {
template <typename U> inline T dot(const SimpleVector<U>& other) const {
assert(entity.size() == other.entity.size());
SimpleVector<T> work(other.size());
#if defined(_OPENMP)
Expand Down Expand Up @@ -4053,6 +4053,58 @@ template <typename T> static inline SimpleVector<T> autoGamma(const SimpleVector
return autoGamma<T>(b, r)[0].row(0);
}

template <typename T> pair<vector<SimpleVector<T> >, vector<SimpleVector<T> > > predvc(const vector<SimpleVector<T> >& in) {
// N.B. we need stable next vectors.
int p0(1);
for( ; p0 < in.size(); p0 ++) {
const auto pp(pnextcacher<T>(in.size(), p0, 4));
if(T(int(in.size())) < sqrt(pp.dot(pp))) break;
}
vector<SimpleVector<T> > p;
if(-- p0 < 1) return make_pair(p, p);
SimpleVector<T> sec(in.size());
for(int i = 0; i < sec.size(); i ++)
sec[i] = makeProgramInvariant<T>(in[i], - T(int(1)), true).second;
auto secb(sec);
for(int i = 0; i < sec.size(); i ++)
secb[i] = sec[sec.size() - i - 1];
p.resize(p0);
auto q(p);
for(int i = 0; i < p0; i ++) {
p[i].resize(in[0].size());
q[i].resize(in[0].size());
p[i].O();
q[i].O();
}
#if defined(_OPENMP)
#pragma omp parallel for schedule(static, 1)
#endif
for(int j = 0; j < in[0].size(); j ++) {
cerr << j << " / " << in[0].size() << endl;
idFeeder<T> pb(sec.size());
idFeeder<T> pf(sec.size());
for(int i = 0; i < in.size(); i ++)
pf.next(makeProgramInvariantPartial<T>(in[i][j], sec[i], true));
assert(pf.full);
for(int k = 0; k < pf.res.size(); k ++)
pb.next(pf.res[pf.res.size() - 1 - k]);
assert(pb.full);
for(int i = 0; i < p0; i ++) {
q[i][j] += P0maxRank0<T>(i + 1).next(pb.res);
p[i][j] += P0maxRank0<T>(i + 1).next(pf.res);
}
}
for(int i = 0; i < p.size(); i ++) {
const auto qsec(P0maxRank0<T>(i + 1).next(secb));
const auto psec(P0maxRank0<T>(i + 1).next(sec));
for(int j = 0; j < p[i].size(); j ++)
p[i][j] = revertProgramInvariant<T>(make_pair(p[i][j], psec), true);
for(int j = 0; j < q[i].size(); j ++)
q[i][j] = revertProgramInvariant<T>(make_pair(q[i][j], qsec), true);
}
return make_pair(move(p), move(q));
}

template <typename T> pair<vector<SimpleVector<T> >, vector<SimpleVector<T> > > predv(const vector<SimpleVector<T> >& in) {
// N.B. we need rich internal status.
const int p0(ceil(sqrt(T(int(in.size() - 4 - 1 + 2 - 4 - 2)) )) );
Expand All @@ -4078,7 +4130,6 @@ template <typename T> pair<vector<SimpleVector<T> >, vector<SimpleVector<T> > >
p[i].O();
q[i].O();
}
const auto one65536(T(int(1)) / T(int(65536)));
#if defined(_OPENMP)
#pragma omp parallel for schedule(static, 1)
#endif
Expand Down Expand Up @@ -4111,7 +4162,7 @@ template <typename T> pair<vector<SimpleVector<T> >, vector<SimpleVector<T> > >
return make_pair(move(p), move(q));
}

template <typename T> pair<vector<vector<SimpleVector<T> > >, vector<vector<SimpleVector<T> > > > predVec(const vector<vector<SimpleVector<T> > >& in0) {
template <typename T, bool continuous = false> pair<vector<vector<SimpleVector<T> > >, vector<vector<SimpleVector<T> > > > predVec(const vector<vector<SimpleVector<T> > >& in0) {
assert(in0.size() && in0[0].size() && in0[0][0].size());
cerr << "ratio: " << ceil(T(int(in0[0].size() * in0[0][0].size())) / T(int(in0.size())) / T(int(2))) << endl;
vector<SimpleVector<T> > in;
Expand All @@ -4125,7 +4176,7 @@ template <typename T> pair<vector<vector<SimpleVector<T> > >, vector<vector<Simp
in[i].setVector(j * in0[i][0].size(), in0[i][j]);
}
}
const auto p(predv<T>(in));
const auto p(continuous ? predvc<T>(in) : predv<T>(in));
pair<vector<vector<SimpleVector<T> > >, vector<vector<SimpleVector<T> > > > res;
res.first.resize( p.first.size() );
res.second.resize(p.second.size());
Expand All @@ -4140,7 +4191,7 @@ template <typename T> pair<vector<vector<SimpleVector<T> > >, vector<vector<Simp
return res;
}

template <typename T> pair<vector<vector<SimpleMatrix<T> > >, vector<vector<SimpleMatrix<T> > > > predMat(const vector<vector<SimpleMatrix<T> > >& in0) {
template <typename T, bool continuous = false> pair<vector<vector<SimpleMatrix<T> > >, vector<vector<SimpleMatrix<T> > > > predMat(const vector<vector<SimpleMatrix<T> > >& in0) {
assert(in0.size() && in0[0].size() && in0[0][0].rows() && in0[0][0].cols());
cerr << "ratio: " << ceil(T(int(in0[0].size() * in0[0][0].rows() * in0[0][0].cols())) / T(int(in0.size())) / T(int(2)) ) << endl;
vector<SimpleVector<T> > in;
Expand All @@ -4156,7 +4207,7 @@ template <typename T> pair<vector<vector<SimpleMatrix<T> > >, vector<vector<Simp
k * in0[i][0].cols(), in0[i][j].row(k));
}
}
const auto p(predv<T>(in));
const auto p(continuous ? predvc<T>(in) : predv<T>(in));
pair<vector<vector<SimpleMatrix<T> > >, vector<vector<SimpleMatrix<T> > > > res;
res.first.resize( p.first.size() );
res.second.resize(p.second.size());
Expand All @@ -4181,9 +4232,12 @@ template <typename T> pair<vector<vector<SimpleMatrix<T> > >, vector<vector<Simp
return res;
}

template <typename T> pair<vector<SimpleSparseTensor<T> >, vector<SimpleSparseTensor<T> > > predSTen(const vector<SimpleSparseTensor<T> >& in0, const vector<int>& idx) {
template <typename T, bool continuous = false> pair<vector<SimpleSparseTensor<T> >, vector<SimpleSparseTensor<T> > > predSTen(const vector<SimpleSparseTensor<T> >& in0, const vector<int>& idx) {
assert(idx.size() && in0.size());
cerr << "ratio: " << ceil(T(int(idx.size() * idx.size() * idx.size())) / T(int(in0.size())) / T(int(2))) << endl;
// N.B. the data we target is especially string stream corpus.
// they are incontinuous one, so complementing with continuous stream
// shouldn't improve outputs.
vector<SimpleVector<T> > in;
in.resize(in0.size());
for(int i = 0; i < in0.size(); i ++) {
Expand All @@ -4194,22 +4248,22 @@ template <typename T> pair<vector<SimpleSparseTensor<T> >, vector<SimpleSparseTe
in[i][j * idx.size() * idx.size() + k * idx.size() + m] =
(in0[i][idx[j]][idx[k]][idx[m]] + T(int(1))) / T(int(2));
}
const auto p(predv<T>(in));
auto p(continuous ? predvc<T>(in) : predv<T>(in));
in.resize(0);
pair<vector<SimpleSparseTensor<T> >, vector<SimpleSparseTensor<T> > > res;
res.first.resize( p.first.size() );
res.second.resize(p.second.size());
for(int i = 0; i < p.first.size(); i ++) {
for(int i = 0; i < p.first.size(); i ++)
for(int j = 0; j < idx.size(); j ++)
for(int k = 0; k < idx.size(); k ++)
for(int m = 0; m < idx.size(); m ++) {
res.first[i][ idx[j]][idx[k]][idx[m]] =
p.first[i][ j * idx.size() * idx.size() + k * idx.size() + m] *
T(int(2)) - T(int(1));
p.first[i][j * idx.size() * idx.size() + k * idx.size() + m]
* T(int(2)) - T(int(1));
res.second[i][idx[j]][idx[k]][idx[m]] =
p.second[i][j * idx.size() * idx.size() + k * idx.size() + m] *
T(int(2)) - T(int(1));
p.second[i][j * idx.size() * idx.size() + k * idx.size() + m]
* T(int(2)) - T(int(1));
}
}
return res;
}

Expand Down
4 changes: 2 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
# R.B. https://www.imagemagick.org/Usage/filter/nicolas/#downsample
# From googling, via https://qiita.com/yoya/items/b1590de289b623f18639 .
if(argv[2][- 1] == "q"):
subprocess.call(["convert", line, "-colorspace", "RGB", "-filter", "LanczosRadius", "-distort", "Resize", str(100. * pow(w * h, - .25)) + "%", "-colorspace", "sRGB", "-colorspace", "RGB", "+sigmoidal-contrast", "7.5", "-filter", "LanczosRadius", "-distort", "Resize", str(w) + "x" + str(h) + "!", "-sigmoidal-contrast", "7.5", "-colorspace", "sRGB", root + "-cleansq.png"])
subprocess.call(["convert", line, "-colorspace", "RGB", "-filter", "LanczosRadius", "-distort", "Resize", str(50. * pow(w * h, - .25)) + "%", "-colorspace", "sRGB", "-colorspace", "RGB", "+sigmoidal-contrast", "7.5", "-filter", "LanczosRadius", "-distort", "Resize", str(w) + "x" + str(h) + "!", "-sigmoidal-contrast", "7.5", "-colorspace", "sRGB", root + "-cleansq.png"])
else:
subprocess.call(["convert", line, "-colorspace", "RGB", "-filter", "LanczosRadius", "-distort", "Resize", str(100. * pow(w * h, - .25)) + "%", "-colorspace", "sRGB", root + "-cleans.png"])
subprocess.call(["convert", line, "-colorspace", "RGB", "-filter", "LanczosRadius", "-distort", "Resize", str(200. * pow(w * h, - .25)) + "%", "-colorspace", "sRGB", root + "-cleans.png"])

0 comments on commit 7f8a82a

Please sign in to comment.