<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Coding on The Personal Website of Myosotics</title>
    <link>/categories/coding/</link>
    <description>Recent content in Coding on The Personal Website of Myosotics</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-US</language>
    <lastBuildDate>Fri, 10 Nov 2023 00:00:00 +0000</lastBuildDate><atom:link href="/categories/coding/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Portfolio Selection with Feature Screening</title>
      <link>/blog/2023-11-10-portfolio-selection-with-feature-screening/</link>
      <pubDate>Fri, 10 Nov 2023 00:00:00 +0000</pubDate>
      
      <guid>/blog/2023-11-10-portfolio-selection-with-feature-screening/</guid>
      <description>算法和代码均来自文章：Jin-Hong Du, Yifeng Guo &amp;amp; Xueqin Wang (2023) High-Dimensional Portfolio Selection with Cardinality Constraints, Journal of the American Statistical Association, 118:542, 779-791, DOI: 10.1080/01621459.2022.2133718.
首先加載reticulate包，方便在Rmarkdown中使用Python。
library(reticulate) ## Warning: 程辑包&#39;reticulate&#39;是用R版本4.1.3 来建造的 use_python(&#39;E:/software/Program Files/python3.11.0&#39;) 一个小测试 构建一个数据集用来测试
import numpy as np n = 20 d = 100 np.random.seed(0) X = np.random.rand(n,d) + 0.5 X.shape ## (20, 100) from spo import spo_l1_path ws, lambdas, gaps, n_iters, n_active_features = spo_l1_path(X, func=0, n_lambdas=50, screen=True, max_iter=int(1e4), f=200, tol=1e-3) ## 0%| | 0/50 [00:00&amp;lt;?</description>
    </item>
    
    <item>
      <title>Latex模板讲解——beamer</title>
      <link>/blog/2023-10-22-latex-beamer/</link>
      <pubDate>Sun, 22 Oct 2023 00:00:00 +0000</pubDate>
      
      <guid>/blog/2023-10-22-latex-beamer/</guid>
      <description>导言区 \documentclass{beamer}用以规定文档的类型 beamer 。 参考文献格式设置 \usepackage[citestyle=authoryear,bibstyle=numeric,sorting=ynt]{biblatex}: 即为 引用biblatex包。对于citestyle=authoyear 这里主要解释如下代码：
\documentclass{beamer} % 中文文档，字体，数学，画图包 \usepackage{ctex, hyperref} \usepackage[T1]{fontenc} \usepackage{latexsym,amsmath,xcolor,multicol,booktabs,calligra} \usepackage{graphicx,pstricks,listings,stackengine} \usepackage{SUFE} % SUFE.sty % 参考文献格式和源 \usepackage[citestyle=authoryear,bibstyle=numeric,sorting=ynt]{biblatex} \addbibresource{ref.bib} % 标题页内容 \author[Peijie Fang, Stefan]{方培杰\inst{1} \and 杰培方\inst{2}} % 中括号内为简略名，于底栏显示 \title[SUFE Template]{上海财经大学Beamer模板} \subtitle{上海财经大学Beamer模板} \institute[SUFE] % (optional) { \inst{1}上海财经大学金融学院 \and \inst{2}西安交通大学金禾经济研究中心 } \date[Pre Date]{\today} \begin{document} \kaishu \begin{frame} \titlepage % 显示 \begin{figure}[htpb] % logo \begin{center} \includegraphics[width=0.2\linewidth]{pic/SUFE_Logo.eps} \end{center} \end{figure} \end{frame} \begin{frame} % 设置目录格式，后面每有一个section，本页就会自动显示出来 \tableofcontents[sectionstyle=show,subsectionstyle=show/shaded/hide,subsubsectionstyle=show/shaded/hide] \end{frame} \section{课题背景} \begin{frame}{Beamer简易入门} \begin{itemize}[&amp;lt;+-| alert@+&amp;gt;] % 当然，除了alert，手动在里面插 \pause 也行 \item 很多学校都有自己的Beamer主题 \item 但是上海财经大学没有 \item 中文支持请选择 Xe\LaTeX{} 编译选项 \item \href{http://tug.</description>
    </item>
    
    <item>
      <title>Latex模板讲解</title>
      <link>/blog/2023-10-21-latex/</link>
      <pubDate>Sat, 21 Oct 2023 00:00:00 +0000</pubDate>
      
      <guid>/blog/2023-10-21-latex/</guid>
      <description>导言区 \documentclass{beamer}用以规定文档的类型 beamer 。 class 指定想要的文档类型， 通过 options 参数可以定制文档类的属性，不同的选项之间必须用逗号隔开。 # 源格式 \documentclass[option]{class} # 模板格式 \documentclass[hyperref,UTF8,11pt]{beamer} 11pt是设置文档中所使用字体大小，默认为10pt；UTF-8是设置编码；引入hyperref 后再编译文档时，会根据章节结构，自动生成目录结构的文档标签，同时，正文中的目录和 所有交叉引用，都会自动生为超链接，可以用鼠标点击跳转到引用位置，这是hyperref宏 包在此类文档中的一个缩用。
\usepackage{}是加载宏包
\setbeamersize{}，调整左右两侧的页边距。注意 beamer 幻灯片的尺寸是$128mm \times 96mm$ ， 这个尺寸固定无法修改，但左右两侧的页边距可以修改。此处0.042\paperwidth是指整个 页面纸张paperwith的宽度的$4.2\%$。
\setbeamersize{text margin left=0.042\paperwidth,text margin right=0.042\paperwidth} hyperref宏包用以实现超链接功能，涉及的链接遍布LATEX的每一个角落——目录、 引用、脚注、索引、参考文献等等都被封装成超链接。但这也使得它与其他宏包发生冲突的 可能性大大则更加，故而习惯上将hyperref宏包放在其他宏包之后调用。
hyperref宏包提供了命令\hypersetup配置各种参数。参数也可以作为宏包选项，在调 用宏包时指定： \hypersetup{⟨option1⟩,⟨option2⟩={value},…} \usepackage[⟨option1⟩,⟨option2⟩={value},…]{hyperref} CJKbookmarks=true用以指明是否生成书签。
这里主要解释如下代码：
\documentclass{beamer}%[hyperref,UTF8,11pt] \usepackage{ctex} \usepackage[utf8]{inputenc} \setbeamersize{text margin left=0.042\paperwidth,text margin right=0.042\paperwidth}% 调整左右边距 \usepackage{fontspec} \usepackage{comment} \usepackage{xeCJK} \usepackage{hyperref} \usepackage{graphicx} \usepackage{epstopdf} \usepackage{bm} \usepackage{array} \usepackage{cases} \usepackage{multirow} \usepackage{enumerate} \usepackage{algorithm} \usepackage{algorithmic} \usepackage{xcolor} % 提供对颜色的支持 \usepackage{amsmath, amsfonts, amssymb} % math equations, symbols \usepackage[english]{babel} \usepackage{color} % color content \usepackage{graphicx} % import figures \usepackage{url} % hyperlinks \usepackage{bm} % bold type for equations \usepackage{multirow} \usepackage{booktabs} \usepackage{epstopdf} \usepackage{epsfig} \usepackage{algorithm} \usepackage{algorithmic} \hypersetup{CJKbookmarks=true} \usepackage{url} \usepackage{amsmath} \usepackage{amsthm} \newtheorem{assumption}{假设} \newtheorem{proposition}{性质} \usepackage{booktabs} \usepackage[backend=biber,style=numeric,sorting=none]{biblatex} \beamertemplatetextbibitems \setcounter{tocdepth}{1} \usepackage{subcaption} \usepackage{amsmath} \usepackage{ustcbeamersx} \graphicspath{{image/}} \setsansfont{Microsoft YaHei} % 一般建议是微软雅黑，可以修改成其他字体。 \setCJKmainfont{Microsoft YaHei} %\setCJKmainfont{SimHei} \usefonttheme{professionalfonts} % 第一页的设置 \title[毕业论文答辩]{\zihao{3} 上海财经大学Beamer模板}% 方括号内容显示在页脚，花括号内容是全称 \author{\noindent XXX} \institute[SUFE] { \noindent 上海财经大学2024级\\ \medskip \noindent \textit{ liangyu1096@163.</description>
    </item>
    
    <item>
      <title>Python基础——版本查看及第三方库操作</title>
      <link>/blog/2023-10-19-python/</link>
      <pubDate>Thu, 19 Oct 2023 00:00:00 +0000</pubDate>
      
      <guid>/blog/2023-10-19-python/</guid>
      <description>版本查看 查看python版本 使用cmd命令查看(只能查看默认环境变量的python)。
输入win + r进入命令窗口。输入python即可查看默认的 python 版本。 或者输入python --version命令进行查看 查看python的路径 在命令窗口中输入where python，它会显示python对应的路径，多个版本会显示多个路径 默认的python版本就是cmd进入的python 首先查看高级系统设置并进入环境变量页面 查看环境变量的python。一般查看PATH变量。 第三方库操作 查看第三方库 使用cmd命令查看(只能查看默认环境变量的python) 输入win + r进入命令窗口。输入pip list即可查看安装的第三方库。 通过安装的路径来看python的包 在命令窗口中输入where python，它会显示python对应的路径，多个版本会显示多个路径。 复制进入对应python.exe的的上一级文件，此处我进入的是：E:\software\Program Files\Python 之后一般第三方库的路径实在.\Lib\site-packages中。 手动配置pip镜像源 手动配置，windows下，直接在user目录中创建一个pip目录，再新建文件pip.ini。 接着打开pip.ini文件，复制粘贴以下内容并保存。
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple 注意此处是设置了清华源为例，国内镜像源有如下
清华 https://pypi.tuna.tsinghua.edu.cn/simple 豆瓣 http://pypi.douban.com/simple/ 阿里 http://mirrors.aliyun.com/pypi/simple/ 中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/ 第三方库安装 pip安装大法 在命令行窗口使用pip install packages即可，例如，以安装numba库为例。 </description>
    </item>
    
    <item>
      <title>在Rmarkdown中调用Python代码</title>
      <link>/blog/2023-10-19-rmarkdown-python/</link>
      <pubDate>Thu, 19 Oct 2023 00:00:00 +0000</pubDate>
      
      <guid>/blog/2023-10-19-rmarkdown-python/</guid>
      <description>在Rmarkdown中调用Python代码块需要用到reticulate包
install.packages(&amp;quot;reticulate&amp;quot;) 在我们运行python代码块之前首先需要设置好Python环境。下面我们需要指定Python路径， 在命令窗口输入where python看python的路径 接下来在R中指定Pyrhon路径
library(reticulate) use_python(&#39;E:/software/Program Files/python3.11.0&#39;) 最后即可在Rmarkdown中运行python代码块了
import numpy as np import matplotlib.pyplot as plt # 计算正弦曲线上的 x 和 y 坐标 x = np.arange(0, 3*np.pi, 0.1) y = np.sin(x) plt.title(&#39;sine wave form&#39;) # 使用 matplotlib 来绘制点 plt.plot(x, y) plt.show() </description>
    </item>
    
  </channel>
</rss>
