⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 leastsquares.h

📁 source codes for "Orthant-Wise Limited-memory Quasi-Newton Optimizer for L1-regularized Objectives"
💻 H
字号:
#pragma once

#include <fstream>
#include <string>

#include "OWLQN.h"

struct LeastSquaresObjective;

class LeastSquaresProblem {
	DblVec Amat;
	DblVec b;
	size_t m, n;

	
	void skipEmptyAndComment(std::ifstream& file, std::string& s) {
		do {
			std::getline(file, s);
		} while (s.size() == 0 || s[0] == '%');
	}

	friend struct LeastSquaresObjective;

public:
	LeastSquaresProblem(size_t m, size_t n) : Amat(m * n), b(m), m(m), n(n) { }

	LeastSquaresProblem(const char* matfile, const char* bFile);

	double A(size_t i, size_t j) const {
		return Amat[i + m * j];
	}

	double& A(size_t i, size_t j) {
		return Amat[i + m * j];
	}

	size_t NumFeats() const { return n; }
	size_t NumInstances() const { return m; }
};

struct LeastSquaresObjective : public DifferentiableFunction {
	const LeastSquaresProblem& problem;

	LeastSquaresObjective(const LeastSquaresProblem& p) : problem(p) { }

	double Eval(const DblVec& input, DblVec& gradient) const;
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -