<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="https://jinhongdu-lab.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://jinhongdu-lab.github.io/" rel="alternate" type="text/html" /><updated>2026-07-24T19:26:42-07:00</updated><id>https://jinhongdu-lab.github.io/feed.xml</id><title type="html">Jin-Hong Du</title><subtitle>Assistant Professor at the University of Hong Kong</subtitle><author><name>Jin-Hong Du</name><email>jinhongd@hku.hk</email></author><entry><title type="html">Academic Job Interview</title><link href="https://jinhongdu-lab.github.io/posts/2024/10/blog-job-interview/" rel="alternate" type="text/html" title="Academic Job Interview" /><published>2024-10-13T00:00:00-07:00</published><updated>2024-10-13T00:00:00-07:00</updated><id>https://jinhongdu-lab.github.io/posts/2024/10/job-interview</id><content type="html" xml:base="https://jinhongdu-lab.github.io/posts/2024/10/blog-job-interview/">&lt;h1 id=&quot;screening-interview-questions&quot;&gt;Screening interview questions&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;20-40 mins, 1-4 interviewers&lt;/li&gt;
&lt;li&gt;Jot down names of interviewers at the start.&lt;/li&gt;
&lt;li&gt;Give an answer, then pause. If no follow up - ask if they would like you to expand anything.&lt;/li&gt;
&lt;li&gt;Conversation will end with a chance for you to ask questions
&lt;ul&gt;
&lt;li&gt;ask 2 questions&lt;/li&gt;
&lt;li&gt;I feel that you have answered everything, and I guess my last question is what would be the next step.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;They all tend to have the same structure: you&apos;ll meet with probably multiple members of the search committee (2-5), they&apos;ll ask 3-5 questions, usually taking turns, then give you the chance to ask one or two questions. The types of questions will vary based on the type of school (mainly for teaching vs research focused positions), but could include:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Why THIS school/department/position?&lt;/li&gt;
&lt;li&gt;Describe a course you&apos;d like to teach/what courses are you interested in teaching.&lt;/li&gt;
&lt;li&gt;What are your research plans? (For research focused positions, they might want to know about how you plan to get funding. For teaching focused schools, they may want to know about the feasibility of your work there, re: cost of equipment, likely lack of grad students/postdocs, and involvement of undergraduates)&lt;/li&gt;
&lt;li&gt;How does your work further diversity, equity, and inclusion? (In the classroom, in your research, etc. I often got this question about inclusive teaching specifically when interviewing for teaching positions).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It tended to be variations on those four specific topics (fit, teaching, research, equity), with random additional ones thrown in. Like in other interviews, I&apos;d keep your answers relatively brief, and signal enthusiasm about the job. Good luck!&lt;/p&gt;
&lt;h2 id=&quot;personal&quot;&gt;Personal&lt;/h2&gt;
&lt;details&gt;&lt;summary&gt;&lt;i&gt;&lt;b&gt;Tell us a bit about yourself.&lt;/b&gt;&lt;/i&gt;&lt;/summary&gt;
  Thank you so much for the opportunity of being here. My name is Jin-Hong Du. I am currently fourth-year PhD Candidate at Carnegie Mellon University. I am in the Statistics and Machine Learning joint program. My current research interests lie in semiparametric inference, to combine the predictive strength of machine learning and deep learning methods, with valid statistical inference for high-dimensional outcomes. I have also worked on some applied projects, designing flexible deep generative models for single-cell data analysis. 
&lt;p&gt;And finally, I have also been working on overparameterized learning with other collaborators, and for me, I am more interested in cross-validation for overaprameterized models, because ….&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;&lt;summary&gt;&lt;i&gt;&lt;b&gt;What&apos;s your expectation of being an assistant professor?&lt;/b&gt;&lt;/i&gt;&lt;/summary&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Research:
I expect to establish a strong research program of statistical methodology and application in the area of single-cell multiomics.
I also hope to establish myself in the field of biological science by collaborating with biologists and medical researchers.
I aim to secure funding from federal agencies such as the National Science Foundation (NSF) and the National Institutes of Health (NIH) to support my research program.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Teaching and Mentorship:
I expect to create an inclusive and engaging learning environment for students, fostering their interest in statistics and machine learning.
I look forward to developing and teaching courses in statistics and machine learning, particularly in high-dimensional statistics and applied regression methods.
I also hope to mentor students at all levels, guiding them through research projects and helping them develop essential skills for their academic and professional careers.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Service: I expect to be actively involved in service within the department, contributing to committees and collaborative projects. I also hope to engage with the broader academic community through conference organization and journal reviewing.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Professional Development and Collaboration:
I look forward to collaborating with colleagues on research projects, sharing my expertise, and learning from others.
I also hope to establish interdisciplinary collaboration with members outside the department, contributing to a diverse and vibrant academic environment.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;h2 id=&quot;interest&quot;&gt;Interest&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;Why are you interested in this position?&lt;/strong&gt;&lt;/em&gt; / &lt;em&gt;&lt;strong&gt;Why do you want this position?&lt;/strong&gt;&lt;/em&gt; / &lt;em&gt;&lt;strong&gt;Why are you interested here? What do you know about our institution?&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To be honest, I don’t know a lot about the area. What I read makes me think it would be a fine place for me.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;What quality make you fit for this position?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;How will this position bring you closer to achieving your academic goals?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;What ideal colleagues are you looking for? Who do you think that you can collaborate with?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;contribution&quot;&gt;Contribution&lt;/h2&gt;
&lt;h3 id=&quot;contribution-to-departmentschooluniversity&quot;&gt;Contribution to department/school/university&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;What can you contribute to our department?&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;What strengths would you be added to your department?&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;What can you contribute to our school and university in addition?&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;contribution-to-the-field&quot;&gt;Contribution to the field&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;What do you hope to contribute to your field during your time at this university?&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;What do you hope to achieve while employed at our institution?&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;contribution-other-than-research-and-teaching&quot;&gt;Contribution other than research and teaching&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;If there is no pressure from research and teaching, what will you do next?&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;research&quot;&gt;Research&lt;/h2&gt;
&lt;details&gt;&lt;summary&gt;&lt;i&gt;&lt;b&gt;Where is your research heading in the next 5-10 years?&lt;/b&gt;&lt;/i&gt;&lt;/summary&gt;
&lt;ul&gt;
&lt;li&gt;Start with some general points.
&lt;ul&gt;
&lt;li&gt;Establish myself in my field of science.&lt;/li&gt;
&lt;li&gt;Emphasize mentoring.&lt;/li&gt;
&lt;li&gt;Securing funding.&lt;/li&gt;
&lt;li&gt;Establishing a productive international scientific network.&lt;/li&gt;
&lt;li&gt;Impact on society.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Specific points.
&lt;ul&gt;
&lt;li&gt;Do you know how to get to these goals? Are the goals realistic? What do you need?&lt;/li&gt;
&lt;li&gt;Embed this in the long-term career goal.&lt;/li&gt;
&lt;li&gt;Ideally, immediate goals, 5-year goals, and career goals.&lt;/li&gt;
&lt;li&gt;Explain the importance of collaboration (with people in the department). Well, I can envision something like a research unit on this broader topic that would fit into my 5-year research goal. That is also going be interesting to other research members in your department. These members could be ....&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Example: My long-term goal is to achieve .... During my first 5 years here I want to make decisive progress towards the milestone of .... I can engageing collaborations with the other department members because they would help me ... and increase the scope in such and such a way to help me achieve part of these goals and this would also have the added benefit of adding this particular question/approach/theory of ... to the portfolio of the department. To achieve this I will need .... This is important because society really really needs answers to the question of ... and this is why I believe there is a really good chance to get this work funded by funding agency ....&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;&lt;summary&gt;&lt;i&gt;&lt;b&gt;What research resources will you need to be successful?&lt;/b&gt;&lt;/i&gt;&lt;/summary&gt;
  computation
&lt;/details&gt;
&lt;details&gt;&lt;summary&gt;&lt;i&gt;&lt;b&gt;What is the status of the publications you listed as &apos;in preparation&apos; or &apos;under review&apos;?&lt;/b&gt;&lt;/i&gt;&lt;/summary&gt;
&lt;/details&gt;
&lt;p&gt;Tell us about your research interest/ What is your research expertise?
Your future research plan/your research vision?
Why is your research important in xx field?
How will you build and support your research program?&lt;/p&gt;
&lt;h2 id=&quot;teaching&quot;&gt;Teaching&lt;/h2&gt;
&lt;details&gt;&lt;summary&gt;&lt;i&gt;&lt;b&gt;What is your teaching experience? / What courses have you taught previously?&lt;/b&gt;&lt;/i&gt;&lt;/summary&gt;
&lt;p&gt;While I haven&apos;t had the opportunity to teach a full course independently yet, I have gained valuable teaching experience through my roles as a teaching assistant at both Carnegie Mellon University during my PhD and at the University of Chicago during my Master&apos;s program.&lt;/p&gt;
&lt;p&gt;For instance, I served as a TA for STAT 32940: Multivariate Data Analysis and Visualization at the University of Chicago. In this role, I supported students with diverse needs, particularly in interdisciplinary subjects like statistics. I also proposed new homework problems categorized into different levels of difficulty, which helped students progress through increasingly challenging material.&lt;/p&gt;
&lt;p&gt;Additionally, I&apos;ve been involved in mentoring junior students, guiding them through complex statistical concepts and methods. For example, I&apos;ve helped students understand and apply clustering algorithms, guiding them in interpreting results meaningfully.&lt;/p&gt;
&lt;p&gt;While these experiences aren&apos;t full course instruction, they&apos;ve provided me with a strong foundation in teaching principles and practices. I&apos;m eager to apply these skills and my teaching philosophy to develop and lead full courses in the future, particularly in areas such as high-dimensional statistics, overparameterized learning, generalized linear regression, modern methods in applied statistics, and statistical computing.&amp;quot;&lt;/p&gt;
&lt;p&gt;This response acknowledges your lack of full course teaching experience while emphasizing your relevant teaching and mentoring experiences. It also shows your enthusiasm and readiness to take on full course responsibilities in the future.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;&lt;summary&gt;&lt;i&gt;&lt;b&gt;What will be the course you plan to first teach? How would you teach our students?&lt;/b&gt;&lt;/i&gt;&lt;/summary&gt;
&lt;/details&gt;
&lt;details&gt;&lt;summary&gt;&lt;i&gt;&lt;b&gt;What can you teach? What would you like to teach?&lt;/b&gt;&lt;/i&gt;&lt;/summary&gt;
&lt;p&gt;While I would love to teaching ..., I&apos;m open to filling needs in the department as well.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;&lt;summary&gt;&lt;i&gt;&lt;b&gt;Tell us how you deal with a classroom of students with different abilities and levels of motivation?&lt;/b&gt;&lt;/i&gt;&lt;/summary&gt;
&lt;/details&gt;
&lt;details&gt;&lt;summary&gt;&lt;i&gt;&lt;b&gt;How do you deal with developing a new course?&lt;/b&gt;&lt;/i&gt;&lt;/summary&gt;
&lt;/details&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;What is your pedagogical principle? / teaching goal?&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;Describe an excellent lecture you delivered and how did you prepare for it?&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;What type of courses would you like to teach?&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;dei&quot;&gt;DEI&lt;/h2&gt;
&lt;details&gt;&lt;summary&gt;&lt;i&gt;&lt;b&gt;Tell me about your commitment to diversity, What will you do to encourage participation and diversity at our school?&lt;/b&gt;&lt;/i&gt;&lt;/summary&gt;
  My commitment to diversity is deeply rooted in my personal experiences as a first-generation college student and my academic journey. 
  To encourage participation and diversity at the school, I would create an inclusive learning environment that supports diverse student needs, such as providing tailored explanations for students with different backgrounds. 
  I would also actively mentor students from diverse backgrounds on research projects, fostering a supportive environment that helps them develop essential skills for academic and professional success. 
  Additionally, I would integrate DEI principles into my research by focusing on real-world problems that affect underrepresented groups, contributing to the advancement of statistics and science while addressing important societal issues.
&lt;/details&gt;
&lt;h2 id=&quot;grant&quot;&gt;Grant&lt;/h2&gt;
&lt;details&gt;&lt;summary&gt;&lt;i&gt;&lt;b&gt;What will be your grant proposal? Which institute? Timeline?&lt;/b&gt;&lt;/i&gt;&lt;/summary&gt;
  I will try to submit grant proposal to NSF in the fall of the second year after getting a job.
  This will be submitted to the Statistics Program of the Division of Mathematical Sciences (DMS) in the Directorate for Mathematical and Physical Sciences (MPS) at the National Science Foundation (NSF).
  At the same time, I will try to find collaborator, who have been successful in getting grants, to submit a grant proposal to the National Institutes of Health (NIH), as an co-investigators.
  In the third year, after I get more experience on grant writing, I will submit my R01 to NIH and the division will depend on the collaborators and the application we work on.
&lt;/details&gt;
&lt;h2 id=&quot;my-questions&quot;&gt;My questions&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Questions that you have about us?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the culture of the department / research center / institution&lt;/li&gt;
&lt;li&gt;research themes and areas of focus&lt;/li&gt;
&lt;li&gt;the type and amount of teaching duties&lt;/li&gt;
&lt;li&gt;how do people get students, what&apos;s the quality,  what are the numbers, postdocs, etc&lt;/li&gt;
&lt;li&gt;Have schools met with their junior faculty to talk about the tenure clock? Have they reached out to provide extra resources? Is there management training? Is there a strong office, a career office  or graduate student office to support them in supporting their students? You want to know about resources and core facilities, what their expectations are, how tenure and salary policies are set.&lt;/li&gt;
&lt;li&gt;Ask people their personal views of the department, the school, the  area, the chair, and then anything important to you personally or professionally. How are the  schools in this area? Is this a place that really embraces diversity, that&apos;s  working hard on issues of social justice?&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;others&quot;&gt;Others&lt;/h2&gt;
&lt;details&gt;&lt;summary&gt;&lt;i&gt;&lt;b&gt;When are you available to start?&lt;/b&gt;&lt;/i&gt;&lt;/summary&gt;
  Ideally, I like to start wait until …. But for the right position, I am flexible.
&lt;/details&gt;
&lt;details&gt;&lt;summary&gt;&lt;i&gt;&lt;b&gt;If we give you an offer, would you take it?&lt;/b&gt;&lt;/i&gt;&lt;/summary&gt;
  I&apos;m very excited about this position and believe it aligns well with my career goals. I would certainly give serious consideration to any offer you extend.
&lt;p&gt;Need to know more information about the offer, such as the salary range, benefits, and job responsibilities before making a final decision, but I&apos;m certainly looking forward to the possibility of joining your department.&lt;/p&gt;
&lt;/details&gt;
&lt;h1 id=&quot;one-on-one-interview-questions&quot;&gt;One-on-one interview questions&lt;/h1&gt;
&lt;p&gt;Ask for schedule before the visit day.&lt;/p&gt;
&lt;p&gt;The questions to answer:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Do you have some questions on the department?&lt;/li&gt;
&lt;li&gt;What do you want to teach?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The questions to ask:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What are you working currently that you are excited about?&lt;/li&gt;
&lt;li&gt;teaching load&lt;/li&gt;
&lt;li&gt;How many students do you have?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Fill out the time&lt;/p&gt;
&lt;p&gt;Dean/chair&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;non-technical elevator talk&lt;/li&gt;
&lt;li&gt;What&apos;s your vision for the department?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;non evaluated interview&lt;/p&gt;
&lt;h1 id=&quot;communication-and-presentation&quot;&gt;Communication and presentation&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Think Fast, Talk Smart: Communication Techniques &lt;a href=&quot;https://www.youtube.com/watch?v=HAnw168huqA&amp;amp;ab_channel=StanfordGraduateSchoolofBusiness&quot;&gt;Youtube&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Spontaneous speaking:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Get out of your own way. Dare to be dull.&lt;/li&gt;
&lt;li&gt;Reframe the situation as an opportunity.&lt;/li&gt;
&lt;li&gt;Slow down and listen.&lt;/li&gt;
&lt;li&gt;Tell a story.
&lt;ol&gt;
&lt;li&gt;structure 1: problem/opportunity, solution, benefits.&lt;/li&gt;
&lt;li&gt;structure 2: what? so what? now what?&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;resources&quot;&gt;Resources&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Interviewing for Academic Faculty Positions from NIH: &lt;a href=&quot;https://www.youtube.com/watch?v=ZQMLvFvL9rY&amp;amp;t=4749s&amp;amp;ab_channel=NIHOITE&quot;&gt;Youtube&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Interviewing for Academic Faculty Positions in Science: &lt;a href=&quot;https://www.youtube.com/watch?v=c6k7gcvHIUk&amp;amp;ab_channel=Lifeinacademia&quot;&gt;Youtube&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Try to also talk with LLM! &apos;Can you give me a mock interview?&apos;&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Jin-Hong Du</name><email>jinhongd@hku.hk</email></author><category term="Job" /><summary type="html">Screening interview questions</summary></entry><entry><title type="html">Python Handbook</title><link href="https://jinhongdu-lab.github.io/posts/2024/04/blog-python/" rel="alternate" type="text/html" title="Python Handbook" /><published>2024-04-30T00:00:00-07:00</published><updated>2024-04-30T00:00:00-07:00</updated><id>https://jinhongdu-lab.github.io/posts/2024/04/python</id><content type="html" xml:base="https://jinhongdu-lab.github.io/posts/2024/04/blog-python/">&lt;h1 id=&quot;conda&quot;&gt;Conda&lt;/h1&gt;
&lt;p&gt;Install &lt;code&gt;mamba&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;conda &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;mamba &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; base &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; conda-forge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Remove environment:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;conda remove &lt;span class=&quot;nt&quot;&gt;--name&lt;/span&gt; r_env &lt;span class=&quot;nt&quot;&gt;--all&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;For MacOS, override your default platform osx-arm64 and replace it with osx-64:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;CONDA_SUBDIR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;osx-64 mamba create &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; renv
mamba activate renv
conda config &lt;span class=&quot;nt&quot;&gt;--env&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--set&lt;/span&gt; subdir osx-64
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Tensorflow-gpu in conda &lt;a href=&quot;https://stackoverflow.com/questions/75037100/libdevice-not-found-tensorflow&quot;&gt;(Reference)&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;XLA_FLAGS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;--xla_gpu_cuda_data_dir&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$CONDA_PREFIX&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Create a conda environment from an &lt;code&gt;environment.yml&lt;/code&gt; file:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;conda &lt;span class=&quot;nb&quot;&gt;env &lt;/span&gt;create &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; environment.yml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h1 id=&quot;setup-of-r-environment&quot;&gt;Setup of R environment&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands&quot;&gt;(Reference)&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mamba create &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; r_env &lt;span class=&quot;nt&quot;&gt;-y&lt;/span&gt;

conda activate r_env
conda config &lt;span class=&quot;nt&quot;&gt;--add&lt;/span&gt; channels bioconda
conda config &lt;span class=&quot;nt&quot;&gt;--add&lt;/span&gt; channels conda-forge
&lt;span class=&quot;c&quot;&gt;# conda config --set channel_priority strict&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# conda config --set channel_priority false&lt;/span&gt;

mamba &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;r-base&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;4.1.1 &lt;span class=&quot;nt&quot;&gt;-y&lt;/span&gt;
mamba &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; conda-forge &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; bioconda r-seurat r-seuratdisk r-signac &lt;span class=&quot;nt&quot;&gt;-y&lt;/span&gt;
mamba &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; bioconda bioconductor-genomeinfodbdata &lt;span class=&quot;nt&quot;&gt;-y&lt;/span&gt;
mamba &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; bioconda bioconductor-genomeinfodbdata &lt;span class=&quot;nt&quot;&gt;--force-reinstall&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h1 id=&quot;jupyter-notebook&quot;&gt;Jupyter Notebook&lt;/h1&gt;
&lt;h2 id=&quot;python-kernel&quot;&gt;Python kernel&lt;/h2&gt;
&lt;p&gt;Add a new kernel &lt;code&gt;kernel_name&lt;/code&gt; from a conda environment &lt;code&gt;env&lt;/code&gt; &lt;a href=&quot;https://stackoverflow.com/questions/28831854/how-do-i-add-python3-kernel-to-jupyter-ipython&quot;&gt;(Reference)&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;conda activate &lt;span class=&quot;nb&quot;&gt;env
&lt;/span&gt;mamba &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;ipykernel &lt;span class=&quot;nt&quot;&gt;-y&lt;/span&gt;
python &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; ipykernel &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--name&lt;/span&gt; kernel_name
conda deactivate
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;r-kernel&quot;&gt;R kernel&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/IRkernel/IRkernel&quot;&gt;(Reference)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Add a new R kernel &lt;code&gt;kernel_name&lt;/code&gt; from a conda environment &lt;code&gt;r_env&lt;/code&gt; to another conda environment &lt;code&gt;env&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;conda activate r_env
mamba &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;r-irkernel &lt;span class=&quot;nt&quot;&gt;-y&lt;/span&gt;

conda activate &lt;span class=&quot;nb&quot;&gt;env&lt;/span&gt;
/raid6/Jinhong/anaconda3/envs/r_env/bin/R &lt;span class=&quot;nt&quot;&gt;-e&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;IRkernel::installspec(name=&quot;kernel_name&quot;, displayname=&quot;kernel_name&quot;)&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h1 id=&quot;bash-commands&quot;&gt;Bash commands&lt;/h1&gt;
&lt;h2 id=&quot;running-scripts&quot;&gt;Running scripts&lt;/h2&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;nohup &lt;/span&gt;python &lt;span class=&quot;nt&quot;&gt;-u&lt;/span&gt; foo.py 0 &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; foo.out 2&amp;gt;&amp;amp;1 &amp;amp;

&lt;span class=&quot;nb&quot;&gt;nohup &lt;/span&gt;Rscript foo.R 0 &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; foo.out 2&amp;gt;&amp;amp;1 &amp;amp;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;python-dependencies&quot;&gt;Python dependencies&lt;/h2&gt;
&lt;p&gt;Print the versions of Python packages in the current conda environment:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;conda list &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;python|numpy|numba|scipy|pandas|scikit-learn|h5py|anndata|scanpy|statsmodels|matplotlib|joblib|cvxpy|tqdm&quot;&lt;/span&gt; | &lt;span class=&quot;nb&quot;&gt;awk&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;{ print $1&quot; | &quot;$2 }&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;r-dependencies&quot;&gt;R dependencies&lt;/h2&gt;
&lt;h1 id=&quot;linux&quot;&gt;Linux&lt;/h1&gt;
&lt;h2 id=&quot;system-monitoring&quot;&gt;System monitoring&lt;/h2&gt;
&lt;p&gt;System information:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# for basic system info&lt;/span&gt;
landscape-sysinfo

&lt;span class=&quot;c&quot;&gt;# for detailed system info&lt;/span&gt;
top
htop
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;System update:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt update &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt upgrade &lt;span class=&quot;nt&quot;&gt;-y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;reboot
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;file-management&quot;&gt;File management&lt;/h2&gt;
&lt;p&gt;Delete all files with a certain pattern in the current directory and subdirectories &lt;a href=&quot;https://unix.stackexchange.com/questions/116389/recursively-delete-all-files-with-a-given-extension&quot;&gt;(Reference)&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find &lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-type&lt;/span&gt; f &lt;span class=&quot;nt&quot;&gt;-name&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;*.o&apos;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-delete&lt;/span&gt;
find &lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-type&lt;/span&gt; f &lt;span class=&quot;nt&quot;&gt;-name&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;*.o&apos;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-exec&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;rm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{}&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;rm&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;**&lt;/span&gt;/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;.o
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Compress all files in the current directory and subdirectories with a certain pattern:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;zip &lt;span class=&quot;nt&quot;&gt;-r&lt;/span&gt; archive.zip results/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-i&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;*gears*&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Create a symbolic link for a folder:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;ln&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; /path/to/original/directory /path/to/link/location/link_name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Sync files from remote server:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rsync &lt;span class=&quot;nt&quot;&gt;-avu&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--info&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;progress2 jinhongd@hydra1.stat.cmu.edu:/path /path

&lt;span class=&quot;c&quot;&gt;# Example: sync all .sh scripts from source to destination&lt;/span&gt;
rsync &lt;span class=&quot;nt&quot;&gt;-zarv&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--include&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;*/&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--include&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;*.sh&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--exclude&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;*&quot;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$from&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$to&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;user-management&quot;&gt;User management&lt;/h2&gt;
&lt;p&gt;On most Linux servers, create a user with:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;adduser USERNAME
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Set or reset the password:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;passwd USERNAME
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Give access to a shared folder:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; /data/USERNAME
&lt;span class=&quot;nb&quot;&gt;sudo chown&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt; USERNAME:USERNAME /data/USERNAME
&lt;span class=&quot;nb&quot;&gt;sudo chmod &lt;/span&gt;711 /data
&lt;span class=&quot;nb&quot;&gt;sudo chmod &lt;/span&gt;700 /data/USERNAME
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;code&gt;711&lt;/code&gt; on &lt;code&gt;/data&lt;/code&gt; allows the user to enter the directory without listing everyone else’s files.&lt;/p&gt;
&lt;p&gt;conda/mamba environment for multiple users:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;groupadd micromamba
&lt;span class=&quot;nb&quot;&gt;sudo chgrp&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt; micromamba /data/miniforge3
&lt;span class=&quot;nb&quot;&gt;sudo chmod &lt;/span&gt;770 &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt; /data/miniforge3

&lt;span class=&quot;c&quot;&gt;# Each user who wants to use anaconda must be added to that group. Note that you need to log out or otherwise refresh your shell to see your new membership.&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;adduser USERNAME micromamba

&lt;span class=&quot;c&quot;&gt;# Last, each user who wants to use conda needs to add it to their path. This can be done following the instructions in the installation doc:&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;source&lt;/span&gt; /data/miniforge3/bin/activate
conda init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;docker&quot;&gt;Docker&lt;/h2&gt;
&lt;p&gt;Dependencies: &lt;a href=&quot;https://stackoverflow.com/questions/76876492/unable-to-install-docker-on-ubuntu-22-04-2&quot;&gt;https://stackoverflow.com/questions/76876492/unable-to-install-docker-on-ubuntu-22-04-2&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Permission for apt: &lt;a href=&quot;https://askubuntu.com/questions/908800/what-does-this-apt-error-message-download-is-performed-unsandboxed-as-root&quot;&gt;https://askubuntu.com/questions/908800/what-does-this-apt-error-message-download-is-performed-unsandboxed-as-root&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Docker Desktop: &lt;a href=&quot;https://docs.docker.com/desktop/setup/install/linux/ubuntu/&quot;&gt;https://docs.docker.com/desktop/setup/install/linux/ubuntu/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Enable lingering for the user: This ensures that the user&apos;s systemd services, including the rootless Docker daemon, can continue running even after the user logs out.
Code&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;loginctl enable-linger &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;whoami&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Replace $(whoami) with the actual username if performing this for a different user.&lt;/p&gt;
&lt;h2 id=&quot;vpn--proxy-checking-and-node-selection-on-linux-server&quot;&gt;VPN / Proxy Checking and Node Selection on Linux Server&lt;/h2&gt;
&lt;p&gt;This server uses &lt;code&gt;mihomo&lt;/code&gt; as a Clash-compatible proxy backend.&lt;/p&gt;
&lt;p&gt;Default local endpoints:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# HTTP + SOCKS mixed proxy&lt;/span&gt;
http://127.0.0.1:7890

&lt;span class=&quot;c&quot;&gt;# Mihomo external controller API&lt;/span&gt;
http://127.0.0.1:9000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The proxy group used for manual node switching is usually:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Proxy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If the group name is different, list all groups first.&lt;/p&gt;
&lt;hr /&gt;
&lt;h3 id=&quot;check-whether-mihomo-is-running&quot;&gt;1. Check whether mihomo is running&lt;/h3&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;systemctl status mihomo &lt;span class=&quot;nt&quot;&gt;--no-pager&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Expected status:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Active: active (running)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Check whether the proxy and controller ports are listening:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ss &lt;span class=&quot;nt&quot;&gt;-lntp&lt;/span&gt; | &lt;span class=&quot;nb&quot;&gt;grep&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-E&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;7890|9000&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Expected output should include something like:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;127.0.0.1:7890
127.0.0.1:9000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If &lt;code&gt;7890&lt;/code&gt; is missing, the proxy port is not running.&lt;/p&gt;
&lt;p&gt;If &lt;code&gt;9000&lt;/code&gt; is missing, the external controller is not running, and node switching by &lt;code&gt;curl&lt;/code&gt; will not work.&lt;/p&gt;
&lt;hr /&gt;
&lt;h3 id=&quot;check-mihomo-config-path&quot;&gt;2. Check mihomo config path&lt;/h3&gt;
&lt;p&gt;The systemd service usually starts mihomo with:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/usr/local/bin/mihomo &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; /etc/mihomo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;So the active config file should be:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/etc/mihomo/config.yaml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Check important fields:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo grep&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-nE&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;mixed-port|external-controller|secret|proxies:|proxy-groups:|rules:&apos;&lt;/span&gt; /etc/mihomo/config.yaml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The config should include something like:&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;mixed-port&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;7890&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;external-controller&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;127.0.0.1:9000&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;secret&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;It should also include:&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;proxies&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;proxy-groups&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;rules&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If the config only has something like:&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;mixed-port&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;7890&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;then mihomo is running with an incomplete config and has no usable nodes.&lt;/p&gt;
&lt;hr /&gt;
&lt;h3 id=&quot;test-the-proxy-endpoint&quot;&gt;3. Test the proxy endpoint&lt;/h3&gt;
&lt;p&gt;Check whether traffic can go through the proxy:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;-x&lt;/span&gt; http://127.0.0.1:7890 https://ipinfo.io
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;A successful response should show the outbound IP information.&lt;/p&gt;
&lt;p&gt;Test Claude API connectivity:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;HTTPS_PROXY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;http://127.0.0.1:7890 curl &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; https://api.anthropic.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Test OpenAI / Codex connectivity:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;HTTPS_PROXY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;http://127.0.0.1:7890 curl &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; https://api.openai.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;HTTP status codes such as &lt;code&gt;401&lt;/code&gt;, &lt;code&gt;403&lt;/code&gt;, or &lt;code&gt;404&lt;/code&gt; usually mean the network path is reachable but authentication or endpoint details are missing.&lt;/p&gt;
&lt;p&gt;Network-level failures look like:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Connection refused
Could not resolve host
Operation timed out
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;h3 id=&quot;check-whether-the-controller-api-works&quot;&gt;4. Check whether the controller API works&lt;/h3&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; http://127.0.0.1:9000/proxies | jq
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If this fails with:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Connection refused
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;then the controller is not listening on port &lt;code&gt;9000&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Check logs:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;journalctl &lt;span class=&quot;nt&quot;&gt;-u&lt;/span&gt; mihomo &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; 100 &lt;span class=&quot;nt&quot;&gt;--no-pager&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Look for messages related to config parsing, controller startup, or listening ports.&lt;/p&gt;
&lt;hr /&gt;
&lt;h3 id=&quot;list-all-proxy-groups&quot;&gt;5. List all proxy groups&lt;/h3&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; http://127.0.0.1:9000/proxies | jq &lt;span class=&quot;nt&quot;&gt;-r&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;.proxies | keys[]&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Typical groups may include:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Proxy
Auto
DIRECT
GLOBAL
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The manually switchable group is usually &lt;code&gt;Proxy&lt;/code&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;h3 id=&quot;show-available-nodes-in-the-codeproxycode-group&quot;&gt;6. Show available nodes in the &lt;code&gt;Proxy&lt;/code&gt; group&lt;/h3&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; http://127.0.0.1:9000/proxies | jq &lt;span class=&quot;nt&quot;&gt;-r&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;.proxies[&quot;Proxy&quot;].all[]&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Show the currently selected node:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; http://127.0.0.1:9000/proxies | jq &lt;span class=&quot;nt&quot;&gt;-r&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;.proxies[&quot;Proxy&quot;].now&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If this returns &lt;code&gt;null&lt;/code&gt;, the group name may not be &lt;code&gt;Proxy&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;List all groups again:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; http://127.0.0.1:9000/proxies | jq &lt;span class=&quot;nt&quot;&gt;-r&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;.proxies | keys[]&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Then replace &lt;code&gt;Proxy&lt;/code&gt; with the correct group name.&lt;/p&gt;
&lt;hr /&gt;
&lt;h3 id=&quot;manually-switch-node&quot;&gt;7. Manually switch node&lt;/h3&gt;
&lt;p&gt;Switch the &lt;code&gt;Proxy&lt;/code&gt; group to &lt;code&gt;Auto&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;-X&lt;/span&gt; PUT &lt;span class=&quot;s1&quot;&gt;&apos;http://127.0.0.1:9000/proxies/Proxy&apos;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;-H&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;Content-Type: application/json&apos;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;--data&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;{&quot;name&quot;:&quot;Auto&quot;}&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Switch to a specific node:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;-X&lt;/span&gt; PUT &lt;span class=&quot;s1&quot;&gt;&apos;http://127.0.0.1:9000/proxies/Proxy&apos;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;-H&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;Content-Type: application/json&apos;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;--data&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;{&quot;name&quot;:&quot;NODE_NAME_HERE&quot;}&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;-X&lt;/span&gt; PUT &lt;span class=&quot;s1&quot;&gt;&apos;http://127.0.0.1:9000/proxies/Proxy&apos;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;-H&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;Content-Type: application/json&apos;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;--data&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;{&quot;name&quot;:&quot;日本-PRO-FW-JP1-流量倍率:0.2&quot;}&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Confirm the selected node:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; http://127.0.0.1:9000/proxies | jq &lt;span class=&quot;nt&quot;&gt;-r&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;.proxies[&quot;Proxy&quot;].now&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;h3 id=&quot;useful-helper-script-codeswitch-nodecode&quot;&gt;8. Useful helper script: &lt;code&gt;switch-node&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Create a command-line helper:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo tee&lt;/span&gt; /usr/local/bin/switch-node &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; /dev/null &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EOF&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
#!/usr/bin/env bash
set -euo pipefail

API=&quot;http://127.0.0.1:9000&quot;
GROUP=&quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;GROUP&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Proxy&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;

if [ &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$# &lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;-eq 0 ]; then
  echo &quot;Current node:&quot;
  curl -s &quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$API&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;/proxies&quot; | jq -r &quot;.proxies[&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$GROUP&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;].now&quot;

  echo
  echo &quot;Available nodes:&quot;
  curl -s &quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$API&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;/proxies&quot; | jq -r &quot;.proxies[&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$GROUP&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;].all[]&quot;
  exit 0
fi

NODE=&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$*&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;

curl -s -X PUT &quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$API&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;/proxies/&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$GROUP&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;
  -H &apos;Content-Type: application/json&apos; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;
  --data &quot;{&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$NODE&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;}&quot; &amp;gt;/dev/null

echo &quot;Switched to:&quot;
curl -s &quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$API&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;/proxies&quot; | jq -r &quot;.proxies[&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$GROUP&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;].now&quot;
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EOF

&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo chmod&lt;/span&gt; +x /usr/local/bin/switch-node
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Usage:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# Show current node and available nodes&lt;/span&gt;
switch-node

&lt;span class=&quot;c&quot;&gt;# Switch to Auto&lt;/span&gt;
switch-node Auto

&lt;span class=&quot;c&quot;&gt;# Switch to a specific node&lt;/span&gt;
switch-node 日本-PRO-FW-JP1-流量倍率:0.2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If the proxy group is not named &lt;code&gt;Proxy&lt;/code&gt;, set &lt;code&gt;GROUP&lt;/code&gt; manually:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;GROUP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;YourGroupName&apos;&lt;/span&gt; switch-node
&lt;span class=&quot;nv&quot;&gt;GROUP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;YourGroupName&apos;&lt;/span&gt; switch-node Auto
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;h3 id=&quot;enable-proxy-variables-for-claude--codex--cli-tools&quot;&gt;9. Enable proxy variables for Claude / Codex / CLI tools&lt;/h3&gt;
&lt;p&gt;For the current shell:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;HTTP_PROXY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;http://127.0.0.1:7890
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;HTTPS_PROXY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;http://127.0.0.1:7890
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;ALL_PROXY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;http://127.0.0.1:7890

&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;http_proxy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;http://127.0.0.1:7890
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;https_proxy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;http://127.0.0.1:7890
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;all_proxy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;http://127.0.0.1:7890

&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;NO_PROXY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;localhost,127.0.0.1,::1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;no_proxy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$NO_PROXY&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;For all SSH users, add these variables to:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/etc/profile.d/proxy.sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo tee&lt;/span&gt; /etc/profile.d/proxy.sh &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; /dev/null &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EOF&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;
export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
export ALL_PROXY=http://127.0.0.1:7890

export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
export all_proxy=http://127.0.0.1:7890

export NO_PROXY=localhost,127.0.0.1,::1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
export no_proxy=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$NO_PROXY&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EOF
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;After re-login:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;env&lt;/span&gt; | &lt;span class=&quot;nb&quot;&gt;grep&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-i&lt;/span&gt; proxy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;h3 id=&quot;minimal-daily-workflow&quot;&gt;11. Minimal daily workflow&lt;/h3&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# Check service&lt;/span&gt;
systemctl status mihomo &lt;span class=&quot;nt&quot;&gt;--no-pager&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Check ports&lt;/span&gt;
ss &lt;span class=&quot;nt&quot;&gt;-lntp&lt;/span&gt; | &lt;span class=&quot;nb&quot;&gt;grep&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-E&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;7890|9000&apos;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# List available nodes&lt;/span&gt;
switch-node

&lt;span class=&quot;c&quot;&gt;# Switch node&lt;/span&gt;
switch-node Auto

&lt;span class=&quot;c&quot;&gt;# Test outbound IP&lt;/span&gt;
curl &lt;span class=&quot;nt&quot;&gt;-x&lt;/span&gt; http://127.0.0.1:7890 https://ipinfo.io

&lt;span class=&quot;c&quot;&gt;# Test Claude&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;HTTPS_PROXY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;http://127.0.0.1:7890 curl &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; https://api.anthropic.com

&lt;span class=&quot;c&quot;&gt;# Test OpenAI / Codex&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;HTTPS_PROXY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;http://127.0.0.1:7890 curl &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; https://api.openai.com


&lt;span class=&quot;c&quot;&gt;# If config changes, restart mihomo&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;systemctl restart mihomo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;socks5-based-vpn-on-linux&quot;&gt;SOCKS5-based VPN on Linux&lt;/h2&gt;
&lt;p&gt;Suppose a VPN/proxy client, such as a Trojan client, provides a local SOCKS5 proxy at:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;127.0.0.1:1080
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Test whether the SOCKS5 proxy works:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--socks5-hostname&lt;/span&gt; 127.0.0.1:1080 https://ifconfig.me
curl &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--socks5-hostname&lt;/span&gt; 127.0.0.1:1080 https://api.anthropic.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Use &lt;code&gt;--socks5-hostname&lt;/code&gt; rather than &lt;code&gt;--socks5&lt;/code&gt; so that DNS resolution is also sent through the proxy.&lt;/p&gt;
&lt;p&gt;Some command-line tools do not support SOCKS5 proxies directly. For example, Claude Code respects &lt;code&gt;HTTP_PROXY&lt;/code&gt; and &lt;code&gt;HTTPS_PROXY&lt;/code&gt;, but does not directly support SOCKS5 proxies. If Claude Code shows errors such as &lt;code&gt;ECONNRESET&lt;/code&gt;, bridge the SOCKS5 proxy to a local HTTP proxy using &lt;code&gt;privoxy&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Install &lt;code&gt;privoxy&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt update
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;privoxy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Edit the config:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;nano /etc/privoxy/config
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Add the following lines:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;listen-address 127.0.0.1:8118
forward-socks5t / 127.0.0.1:1080 .
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Restart &lt;code&gt;privoxy&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;systemctl restart privoxy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Then export HTTP proxy variables:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;unset &lt;/span&gt;ALL_PROXY all_proxy
&lt;span class=&quot;nb&quot;&gt;unset &lt;/span&gt;HTTP_PROXY HTTPS_PROXY http_proxy https_proxy

&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;HTTP_PROXY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;http://127.0.0.1:8118
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;HTTPS_PROXY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;http://127.0.0.1:8118
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;NO_PROXY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;localhost,127.0.0.1,::1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Test the HTTP proxy bridge:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--proxy&lt;/span&gt; http://127.0.0.1:8118 https://api.anthropic.com
curl &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--proxy&lt;/span&gt; http://127.0.0.1:8118 https://claude.ai
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Run Claude Code:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;claude
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If it still fails, inspect the proxy-related environment variables:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;env&lt;/span&gt; | &lt;span class=&quot;nb&quot;&gt;grep&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-i&lt;/span&gt; proxy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;A common bad setup is:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;HTTPS_PROXY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;socks5://127.0.0.1:1080
&lt;span class=&quot;nv&quot;&gt;HTTP_PROXY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;socks5://127.0.0.1:1080
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;For Claude Code, use the HTTP proxy bridge instead:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;HTTPS_PROXY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;http://127.0.0.1:8118
&lt;span class=&quot;nv&quot;&gt;HTTP_PROXY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;http://127.0.0.1:8118
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;For browsers, make sure SOCKS5 uses remote DNS. In Firefox, set:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;network.proxy.socks_remote_dns = true
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;For Chrome or Chromium, disabling QUIC may help if HTTPS traffic behaves inconsistently:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;chrome://flags/#enable-quic
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;latex-on-linux&quot;&gt;LaTeX on Linux&lt;/h2&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;texlive-full texlive-latex-recommended
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h1 id=&quot;slurm&quot;&gt;Slurm&lt;/h1&gt;
&lt;p&gt;Check GPU usage on the node &lt;code&gt;n01&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ssh n01 &lt;span class=&quot;s1&quot;&gt;&apos;nvidia-smi -l 1&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Check the status of the jobs:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# all jobs&lt;/span&gt;
squeue &lt;span class=&quot;nt&quot;&gt;-u&lt;/span&gt; jinhongd

&lt;span class=&quot;c&quot;&gt;# pending jobs&lt;/span&gt;
squeue &lt;span class=&quot;nt&quot;&gt;--start&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-u&lt;/span&gt; jinhongd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Check the CPU and memory usage of a job:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# for running jobs&lt;/span&gt;
sacct &lt;span class=&quot;nt&quot;&gt;-e&lt;/span&gt;
sacct &lt;span class=&quot;nt&quot;&gt;--format&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;CPUTime,MaxRSS&quot;&lt;/span&gt;
sacct &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; &amp;lt;job_id&amp;gt; &lt;span class=&quot;nt&quot;&gt;--format&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;user%10,jobname%10,node%10,start%10,end%10,elapsed%10,MaxRS

&lt;span class=&quot;c&quot;&gt;# for finished jobs&lt;/span&gt;
seff &amp;lt;job_id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h1 id=&quot;llm&quot;&gt;LLM&lt;/h1&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;claude &lt;span class=&quot;nt&quot;&gt;--dangerously-skip-permissions&lt;/span&gt;

codex &lt;span class=&quot;nt&quot;&gt;--dangerously-bypass-approvals-and-sandbox&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;codex alias&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; ~/.codex-jing

&lt;span class=&quot;c&quot;&gt;# Login personal&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;CODEX_HOME&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;~/.codex-jing codex login

&lt;span class=&quot;nb&quot;&gt;alias &lt;/span&gt;codex-jing&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;CODEX_HOME=$HOME/.codex-jing codex&apos;&lt;/span&gt;


&lt;span class=&quot;c&quot;&gt;# or add to ~/.bashrc&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;CODEX_HOME_WORK&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$HOME&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/.codex-jing&quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;source&lt;/span&gt; ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Jin-Hong Du</name><email>jinhongd@hku.hk</email></author><category term="Python" /><summary type="html">Conda</summary></entry><entry><title type="html">Divergence Measures</title><link href="https://jinhongdu-lab.github.io/posts/2022/04/blog-divergence/" rel="alternate" type="text/html" title="Divergence Measures" /><published>2022-04-16T00:00:00-07:00</published><updated>2022-04-16T00:00:00-07:00</updated><id>https://jinhongdu-lab.github.io/posts/2022/04/divergence</id><content type="html" xml:base="https://jinhongdu-lab.github.io/posts/2022/04/blog-divergence/">&lt;p&gt;This post summarizes useful results on divergence measurere.&lt;/p&gt;
&lt;h1 id=&quot;divergence-measures&quot;&gt;Divergence Measures&lt;/h1&gt;
&lt;p&gt;Below we use $\mathbb{P}$ and $\mathbb{Q}$ to denote two probability measures.
When they are absolutely continuous with respect to the Lebesgue measure $\lambda$, the Radon–Nikodym derivatives $\frac{\mathrm{d}\mathbb{P}}{\mathrm{d}\lambda}$ and $\frac{\mathrm{d}\mathbb{Q}}{\mathrm{d}\lambda}$ reduce to its density function $p$ and $q$.
Thus, the following definition of divergence measures can be expressed in terms of density functions provided that the density functions exist.
Furthermore, there is no loss of generality in assuming the existence of densities, since any pair of distributions have densities with respect to the base measure $\lambda=\frac{1}{2}(\mathbb{P}+\mathbb{Q})$.&lt;/p&gt;
&lt;h2 id=&quot;total-variation-distance&quot;&gt;Total variation distance&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;total variation (TV)&lt;/strong&gt; distance is defined as follows:
$$TV(\mathbb{P},\mathbb{Q})= \sup\limits_{A\subseteq\Omega}|\mathbb{P}(A)-\mathbb{Q}(A)|.$$
This is a very strong notion of distance. In particular, if the TV is small then the probability of any event under the two distributions must be close.&lt;/p&gt;
&lt;p&gt;If the domain $\Omega$ is discrete and suppose we have two distributions $\mathbb{P}$ and $\mathbb{Q}$ with probability mass functions $p$ and $q$, then
$$\begin{align*}
TV(\mathbb{P},\mathbb{Q})&amp;amp;=1-\sum_{x \in \Omega} \min \{p(x), q(x)\}
\\
&amp;amp;= \sum_{{x \in \Omega: p(x) \geq q(x)}}[p(x)-q(x)]\\
&amp;amp;= \frac{1}{2} \sum_{x \in \Omega}|p(x)-q(x)|
\end{align*}$$
The Total Variation distance also belongs to a popular class of distances between probability distributions. It is an &lt;strong&gt;integral probability metric (IPM)&lt;/strong&gt; (other popular examples of IPMs include the Wasserstein distance). The TV distance can also be written as:
$$TV(\mathbb{P},\mathbb{Q})=\frac{1}{2} \sup_{||f||_{\infty} \leq 1}\left|\mathbb{E}_{X \sim \mathbb{P}}[f(X)]-\mathbb{E}_{Y \sim \mathbb{Q}} [f(Y)]\right|$$&lt;/p&gt;
&lt;h2 id=&quot;squared-hellinger-distance&quot;&gt;Squared Hellinger distance&lt;/h2&gt;
&lt;p&gt;The squared Helligher distance is defined as
$$H^2(\mathbb{P},\mathbb{Q})=\frac{1}{2}\int\left(\sqrt{\frac{\mathrm{d}\mathbb{P}}{\mathrm{d}\lambda}}- \sqrt{\frac{\mathrm{d}\mathbb{Q}}{\mathrm{d}\lambda}}\right)^2\mathrm{d}\lambda$$
We can also define it for corresponding density function (or probability mass functions) $p$ and $q$ as
$$ H^{2}(p,q)={\frac {1}{2}}\int \left({\sqrt {p(x)}}-{\sqrt {q(x)}}\right)^{2}\mathrm{d}x=1-\int {\sqrt {p(x)q(x)}}\mathrm{d}x.$$
The Helligher distance and the squared Helligher distance are bounded by 0 and 1: $$0\leq H^2(\mathbb{P},\mathbb{Q})\leq H(\mathbb{P},\mathbb{Q})\leq 1.$$&lt;/p&gt;
&lt;h2 id=&quot;kullbackleibler-divergence&quot;&gt;Kullback–Leibler divergence&lt;/h2&gt;
&lt;p&gt;$$KL(\mathbb{P}, \mathbb{Q}) = \mathbb{E}_{\mathbb{P}}\left[\log\frac{\mathrm{d}\mathbb{P}}{\mathrm{d}\mathbb{Q}}\right]$$&lt;/p&gt;
&lt;p&gt;$$KL(p, q) = - \int p(x) \log q(x) dx + \int p(x) \log p(x) dx$$&lt;/p&gt;
&lt;h2 id=&quot;chi-square-divergence&quot;&gt;Chi-square divergence&lt;/h2&gt;
&lt;h1 id=&quot;properties&quot;&gt;Properties&lt;/h1&gt;
&lt;h2 id=&quot;comparison&quot;&gt;Comparison&lt;/h2&gt;
&lt;p&gt;$$H^2(\mathbb{P},\mathbb{Q})\leq TV(\mathbb{P},\mathbb{Q})\leq \sqrt{2} H(\mathbb{P},\mathbb{Q}) \lesssim\sqrt{KL(\mathbb{P},\mathbb{Q})} \lesssim \sqrt{\chi^2(\mathbb{P},\mathbb{Q})}$$&lt;/p&gt;
&lt;h2 id=&quot;tenserization&quot;&gt;Tenserization&lt;/h2&gt;
&lt;p&gt;If $X_1,\ldots,X_n\overset{iid}{\sim}\mathbb{P}$, then they are associated with the product measure $\mathbb{P}^n$. What is the relationship between divergence of the produce measure and the individual measure? It turns out that for the KL divergence and Hellinger distance we have
$$\begin{align*}
KL(\mathbb{P}^n, \mathbb{Q}^n) &amp;amp;= n KL(\mathbb{P}, \mathbb{Q})\\
H^2(\mathbb{P}^n,\mathbb{Q})^n &amp;amp;\leq n H^2(\mathbb{P},\mathbb{Q}).
\end{align*}$$&lt;/p&gt;
&lt;h1 id=&quot;example&quot;&gt;Example&lt;/h1&gt;
&lt;p&gt;Suppose $p$ and $q$ are the density function of $\mathcal{N}(\mu_1,\sigma_1^2)$ and $\mathcal{N}(\mu_2,\sigma_2^2)$ respectively, then
$$\begin{align}
KL(p, q) &amp;amp;= - \int p(x) \log q(x) dx + \int p(x) \log p(x) dx\\
&amp;amp;=\frac{1}{2} \log (2 \pi \sigma_2^2) + \frac{\sigma_1^2 + (\mu_1 - \mu_2)^2}{2 \sigma_2^2} - \frac{1}{2} (1 + \log 2 \pi \sigma_1^2)\\
&amp;amp;= \log \frac{\sigma_2}{\sigma_1} + \frac{\sigma_1^2 + (\mu_1 - \mu_2)^2}{2 \sigma_2^2} - \frac{1}{2}
\end{align}$$&lt;/p&gt;</content><author><name>Jin-Hong Du</name><email>jinhongd@hku.hk</email></author><category term="Statistics" /><summary type="html">This post summarizes useful results on divergence measurere.</summary></entry><entry><title type="html">Norm Inequality</title><link href="https://jinhongdu-lab.github.io/posts/2022/04/blog-inequality/" rel="alternate" type="text/html" title="Norm Inequality" /><published>2022-04-16T00:00:00-07:00</published><updated>2022-04-16T00:00:00-07:00</updated><id>https://jinhongdu-lab.github.io/posts/2022/04/inequality</id><content type="html" xml:base="https://jinhongdu-lab.github.io/posts/2022/04/blog-inequality/">&lt;p&gt;This post summarizes some useful inequalities between different norms.&lt;/p&gt;
&lt;h1 id=&quot;norm-equivalence&quot;&gt;Norm Equivalence&lt;/h1&gt;
&lt;p&gt;On any &lt;em&gt;finite-dimensional&lt;/em&gt; vector space over $\mathbb{R}$ or $\mathbb{C}$, all norms are equivalent. This means that for any two norms $\Vert\cdot\Vert_a$ and $\Vert\cdot\Vert_b$, there exists $c_1\geq c_2&amp;gt;0$ such that $$c_1\Vert\cdot\Vert_b \leq \Vert\cdot\Vert_a \leq c_2\Vert\cdot\Vert_b $$
holds for any element in the space.&lt;/p&gt;
&lt;h1 id=&quot;useful-inequalities&quot;&gt;Useful Inequalities&lt;/h1&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Domain&lt;/th&gt;
&lt;th&gt;Inequality&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Vector $x\in\mathbb{R}^n$ with $s=\Vert x\Vert_0\leq n$&lt;/td&gt;
&lt;td&gt;$\Vert x\Vert_{\infty}\leq \Vert x\Vert_{2} \leq \Vert x\Vert_{1} \leq \sqrt{s}\Vert x\Vert_{2} \leq s\Vert x\Vert_{\infty}$&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Spectral domain of Matrix $X\in\mathbb{R}^{n\times d}$ with $r=\text{rank}(X)\leq \min\{n,d\}$&lt;/td&gt;
&lt;td&gt;$\Vert X\Vert_{op}\leq \Vert X\Vert_{F}  \leq \Vert X\Vert_{nuc} \leq \sqrt{r}\Vert X\Vert_{F} \leq r\Vert X\Vert_{op}$&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Matrix $X\in\mathbb{R}^{n\times d}$&lt;/td&gt;
&lt;td&gt;$\frac{1}{\sqrt{d}}\Vert X\Vert_\infty\leq\Vert X\Vert_{op}\leq \sqrt{n} \Vert X\Vert_\infty$ &lt;cr&gt; $\frac{1}{\sqrt{n}}\Vert X\Vert_1\leq \Vert X\Vert_{2,\infty} \leq \Vert X\Vert_{op}\leq \sqrt{d} \Vert X\Vert_{2,\infty} \leq \sqrt{d}\Vert X\Vert_1$&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Note the matrix norms in the spectral domain have similar behaviors as the corresponding vector norms.&lt;/p&gt;
&lt;h1 id=&quot;miscellanies&quot;&gt;Miscellanies&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;$\Vert X\Vert_{1} = \max_{1\leq j\leq d} \Vert X_j \Vert_1$&lt;/li&gt;
&lt;li&gt;$\Vert X\Vert_{2,\infty} = \max_{1\leq j\leq d} \Vert X_j \Vert_2$&lt;/li&gt;
&lt;li&gt;$\Vert X \Vert_{F} = ({\rm tr}(X^{\top}X))^{1/2}$&lt;/li&gt;
&lt;li&gt;$\Vert X \Vert_{nuc} = \Vert X \Vert_{\ast} = \Vert X \Vert_{\rm tr} = {\rm tr}((X^{\top}X)^{1/2})$&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- $\Vert X \Vert_{\ast} \geq \Vert X \Vert_{F}$ --&gt;
&lt;p&gt;$|{\rm tr}(AB)| \leq \Vert A \Vert_{\rm op} \cdot \Vert B \Vert_{\rm tr} \leq \sqrt{\rm rank}(B) \Vert A \Vert_{\rm op} \cdot \Vert B \Vert_{F}$&lt;/p&gt;
&lt;p&gt;For positive semi-definite matrix $A$ and arbitrary $B$, we have
$\lambda_n(B),{\rm tr}(A)\leq {\rm tr}(AB)\leq\lambda_1(B),{\rm tr}(A)$&lt;/p&gt;
&lt;!-- $\Vert ABC \Vert_{F}^2 = tr( C^{\top}B^{\top}A^{\top}ABC ) \leq \Vert B \Vert_{op}^2 \Vert AC \Vert_{F}^2 $ --&gt;</content><author><name>Jin-Hong Du</name><email>jinhongd@hku.hk</email></author><category term="Statistics" /><summary type="html">This post summarizes some useful inequalities between different norms.</summary></entry><entry><title type="html">Reproducing Kernel Hilbert Spaces</title><link href="https://jinhongdu-lab.github.io/posts/2022/03/blog-RKHS/" rel="alternate" type="text/html" title="Reproducing Kernel Hilbert Spaces" /><published>2022-03-22T00:00:00-07:00</published><updated>2022-03-22T00:00:00-07:00</updated><id>https://jinhongdu-lab.github.io/posts/2022/03/RKHS</id><content type="html" xml:base="https://jinhongdu-lab.github.io/posts/2022/03/blog-RKHS/">&lt;p&gt;This post summarizes reproducing kernel Hilbert spaces and mainly follows the lecture slides by &lt;a href=&quot;http://www.stats.ox.ac.uk/~sejdinov/teaching/atml14/Theory_slides1_2014.pdf&quot;&gt;D. Sejdinovic, A. Gretton&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We will mainly be concerned about the field $\mathbb{R}$.&lt;/p&gt;
&lt;h1 id=&quot;elementary-spaces&quot;&gt;Elementary Spaces&lt;/h1&gt;
&lt;p&gt;The following graph from the slides illustrates the reproducing kernel Hilbert spaces (RHKS) pretty well.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://jinhongdu-lab.github.io/images/RKHS.png&quot; alt=&quot;RKHS (D. Sejdinovic, A. Gretton)&quot; /&gt;&lt;/p&gt;
&lt;p&gt;We summarize some important spaces in the following table.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Space&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Characterization&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;vector space&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;normed vector space&lt;/td&gt;
&lt;td&gt;a vector space endowed with a norm, which is also a metric space&lt;/td&gt;
&lt;td&gt;distance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;inner product vector space&lt;/td&gt;
&lt;td&gt;a vector space endowed with an inner product&lt;/td&gt;
&lt;td&gt;angles and orthogonality&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;complete space&lt;/td&gt;
&lt;td&gt;every Cauchy sequence converges in the space&lt;/td&gt;
&lt;td&gt;completeness&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Banach space&lt;/td&gt;
&lt;td&gt;complete normed vector space&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hilbert space&lt;/td&gt;
&lt;td&gt;complete inner product vector space&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;For the following content, we will restrict ourselves to the norm vector space, in which some nice properties can be established.&lt;/p&gt;
&lt;h1 id=&quot;linear-operators&quot;&gt;Linear Operators&lt;/h1&gt;
&lt;p&gt;A linear operator is a function $A:\mathcal{F}\rightarrow\mathcal{G}$ such that $$A(a_1 f_1+a_2f_2)=a_1 A(f_1)+a_2A(f_2),\qquad\forall\ a_1,a_2\in\mathbb{R},f_1,f_2\in\mathcal{F},$$ where $\mathcal{F}$ and $\mathcal{G}$ are two vector spaces over $\mathbb{R}$.
When $\mathcal{G}=\mathbb{R}$, the operators are called functionals.&lt;/p&gt;
&lt;p&gt;If $\mathcal{F}$ and $\mathcal{G}$ are two normed vector spaces over $\mathbb{R}$, then the operator norm of a linear operator $A$ is defined as $$||A||=\sup\limits_{f\in\mathcal{F},||f||_{\mathcal{F}}\leq 1}||Af||_{\mathcal{G}}.$$
In this case, a bounded linear operator is one with finite operator norm.
&lt;strong&gt;bounded operator $\neq$ bounded function&lt;/strong&gt;.&lt;/p&gt;
&lt;h1 id=&quot;continuity&quot;&gt;Continuity&lt;/h1&gt;
&lt;p&gt;If $\mathcal{F}$ and $\mathcal{G}$ are two normed vector spaces over $\mathbb{R}$, then $A:\mathcal{F}\rightarrow\mathcal{G}$ is continuous at $f_0\in\mathcal{F}$ if $\forall\ \epsilon&amp;gt;0$, $\exists\ \delta&amp;gt;0$ such that $||f-f_0||_{\mathcal{F}}&amp;lt;\delta\Rightarrow||Af-Af_0||_{\mathcal{G}}&amp;lt;\epsilon$. If $A$ is continous at any $f\in\mathcal{F}$, then $A$ is continuous on $\mathcal{F}$.&lt;/p&gt;
&lt;p&gt;Let $(\mathcal{F},||\cdot||_{\mathcal{F}})$ and $(\mathcal{G},||\cdot||_{\mathcal{G}})$ be normed linear spaces. If $A$ is a linear operator, then the following three conditions are equivalent:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;$A$ is a bounded operator.&lt;/li&gt;
&lt;li&gt;$A$ is continuous on $\mathcal{F}$.&lt;/li&gt;
&lt;li&gt;$A$ is continuous at one point of $\mathcal{F}$.&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&quot;duality&quot;&gt;Duality&lt;/h1&gt;
&lt;p&gt;If $\mathcal{F}$ is a normed space, then the space $\mathcal{F}^{\ast}$ of continuous linear functionals $A:\mathcal{F} \rightarrow \mathbb{R}$ is called the &lt;em&gt;topological dual&lt;/em&gt; space of $\mathcal{F}$.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;(Riesz representation)&lt;/strong&gt; In a Hilbert space $\mathcal{F}$, for every continous linear functional $A \in \mathcal{F}^{\ast}$, there exists a unique $g \in \mathcal{F}$, such that $Af=\langle f,g\rangle.$&lt;/p&gt;
&lt;p&gt;Riesz representation gives an isomorphism $g\mapsto\langle \cdot, g\rangle_{\mathcal{F}}$ between $\mathcal{F}$ and $\mathcal{F}^{\ast}$ which preserves the inner product in the two spaces.
This implies that dual space of a Hilbert space is also a Hilbert space.&lt;/p&gt;
&lt;h1 id=&quot;isometric-isomorphism&quot;&gt;Isometric isomorphism&lt;/h1&gt;
&lt;p&gt;Two Hilbert spaces $\mathcal{H}_1$ and $\mathcal{H}_2$ is isometrically isomorphic if there exists a linear bijective map $U:\mathcal{H}_1\rightarrow\mathcal{H}_2$ that preserves the inner product, i.e., $\langle h_1,h_2\rangle_{\mathcal{H}_1}=\langle Uh_1,Uh_2\rangle_{\mathcal{H}_1}$.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;(Isometric isomorphism between Hilbert spaces and sequence spaces)&lt;/strong&gt; Every Hilbert space has an orthonormal basis and isometrically isomorphic to $l^2(A)$ for some set $A$.&lt;/p&gt;
&lt;p&gt;When the Hilbert space is separable, then $A$ can be taken as $\mathbb{N}$.&lt;/p&gt;
&lt;h1 id=&quot;rkhs&quot;&gt;RKHS&lt;/h1&gt;
&lt;p&gt;Evaluation functional $\delta_x:f\mapsto f(x)$ can be discontinuous in a Hilbert space $\mathcal{H}$ of functions $\mathcal{X}\rightarrow\mathbb{R}$.&lt;/p&gt;
&lt;p&gt;A Hilbert space $\mathcal{H}$ of functions $\mathcal{X}\rightarrow\mathbb{R}$ is said to be a reproducing kernel Hilbert space (RKHS) if $\delta_x$ is an continuous functional for all $x\in\mathcal{X}$.&lt;/p&gt;
&lt;p&gt;Note that we have restrict the objects in the space to be functionals $\mathcal{X}\rightarrow\mathbb{R}$.&lt;/p&gt;
&lt;p&gt;Norm convergence in a RKHS implies pointwise convergence. If $\lim_{n\rightarrow\infty}||f_n-f||_{\mathcal{H}}=0$, then $\lim_{n\rightarrow\infty}f_n(x)=f(x)$, for all $x\in\mathcal{X}$.&lt;/p&gt;
&lt;h2 id=&quot;reproducing-kernel&quot;&gt;Reproducing kernel&lt;/h2&gt;
&lt;h2 id=&quot;inner-product-between-features&quot;&gt;Inner product between features&lt;/h2&gt;
&lt;h2 id=&quot;positive-definite-function&quot;&gt;Positive definite function&lt;/h2&gt;</content><author><name>Jin-Hong Du</name><email>jinhongd@hku.hk</email></author><category term="Statistics" /><summary type="html">This post summarizes reproducing kernel Hilbert spaces and mainly follows the lecture slides by D. Sejdinovic, A. Gretton.</summary></entry><entry><title type="html">Differential Theory</title><link href="https://jinhongdu-lab.github.io/posts/2021/10/blog-differential-theory/" rel="alternate" type="text/html" title="Differential Theory" /><published>2021-12-21T00:00:00-08:00</published><updated>2021-12-21T00:00:00-08:00</updated><id>https://jinhongdu-lab.github.io/posts/2021/10/differential-theory</id><content type="html" xml:base="https://jinhongdu-lab.github.io/posts/2021/10/blog-differential-theory/">&lt;p&gt;This post summarizes differential theory on convex functions, including directional derivatives, subgradients, and Legendre transformation.&lt;/p&gt;
&lt;h1 id=&quot;characterization-of-smoothness&quot;&gt;Characterization of Smoothness&lt;/h1&gt;
&lt;h2 id=&quot;directional-derivatives&quot;&gt;Directional Derivatives&lt;/h2&gt;
&lt;p&gt;The directional derivative of $f$ at $x$ in the direction $d$ is defined as
$$\nabla_d f(x)=\lim\limits_{t\rightarrow 0+}\frac{f(x+td)-f(x)}{t}$$&lt;/p&gt;
&lt;p&gt;If $f$ is finite-value and convex, then the directional derivative for fixed $x$ is finite sublinear with respect to $d$.&lt;/p&gt;
&lt;h2 id=&quot;subgradients&quot;&gt;Subgradients&lt;/h2&gt;
&lt;p&gt;The &lt;em&gt;subdifferential&lt;/em&gt; $\partial f (x)$ of $f$ at $x$ is the nonempty compact convex set of $\mathbb{R}^n$ whose support function is the directional derivative, i.e. $$\partial f(x)=\{s\in\mathbb{R}^n\mid \langle s, d\rangle \leq \nabla_d f(x),\ \forall\ d\in\mathbb{R}^n\}$$
Any vector $s\in \partial f(x)$ is called a &lt;em&gt;subgradient&lt;/em&gt; of $x$.&lt;/p&gt;
&lt;p&gt;The subgradient can also be defined via the subgradient inequality. We say $s$ is a subgradient of $f$ at $x$ if
$$f(y)\geq f(x)+ \langle s, y-x\rangle,\quad \forall\ z\in\mathbb{R}^n.$$&lt;/p&gt;
&lt;p&gt;Property&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;(Multiplicability) If $f$ is a proper convex function on $\mathbb{R}^n$, then $\partial(\lambda f)=\lambda \partial f,\ \forall\ x\in\mathbb{R}^n,\lambda&amp;gt;0.$&lt;/li&gt;
&lt;li&gt;(Additivity) If $f_1$ and $f_2$\text{ri}( are proper convex functions on $\mathbb{R}^n$, then $\partial(f_1+f_2)\supseteq \partial f_1+ \partial f_2,\ \forall\ x\in\mathbb{R}^n$. If the convex sets $\text{ri}(\text{dom} f_1)\cap \text{ri}(\text{dom} f_1)\neq\varnothing$, then $\partial(f_1+f_2)= \partial f_1+ \partial f_2,\ \forall\ x\in\mathbb{R}^n$.&lt;/li&gt;
&lt;li&gt;(Affine Composition) Let $f(x)=h(Ax)$ where $h$ is a proper convex function on $\mathbb{R}^m$ and $A$ is a linear transform from $\mathbb{R}^n$ to $\mathbb{R}^m$. Then $\partial f\supset A^{\ast}\partial h(Ax),\ \forall\ x\in\mathbb{R}^n$. If $\text{Im}(A)\cap \text{ri}(\text{dom}(h))\neq\varnothing$ or if $h$ is polyhedral and $\text{Im}(A)\cap \text{dom}(h)\neq\varnothing$, then $\partial f= A^{\ast}\partial h(Ax),\ \forall\ x\in\mathbb{R}^n$.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;essential-smoothness-and-essential-strictly-convexity&quot;&gt;Essential Smoothness and Essential Strictly Convexity&lt;/h2&gt;
&lt;p&gt;A proper convex function $f$ on $\mathbb{R}^n$ is &lt;em&gt;essentially smooth&lt;/em&gt; if it satisfies the following conditions for $C=\text{dom}(f)$:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;$C\neq\varnothing$;&lt;/li&gt;
&lt;li&gt;$f$ is differentiable on $C$;&lt;/li&gt;
&lt;li&gt;$\lim\limits_{\substack{x\rightarrow x_0\\ x\in C}}|\nabla f(x)|=+\infty$ for all $x_0\in\text{bd}(f)$, which is equivalent to $\partial f(x_0)=\varnothing$ for all $x_0\in\text{bd}(f)$.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The subtle difference between essential smoothness and smoothness lies in the boundary behavior of the gradient.
A smooth convex function on $\mathbb{R}^n$ is in particular essentially smooth.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;(Essential Smoothness and Subgradient)&lt;/strong&gt; If $f$ is a closed proper convex function, then $f$ is essentially smooth if and only if
$$\partial f=\begin{cases}{\nabla f}&amp;amp;\quad x\in\text{int}(\text{dom}(f)),\\\varnothing&amp;amp;,\quad x\not\in\text{int}(\text{dom}(f)).\end{cases}$$&lt;/p&gt;
&lt;p&gt;A proper convex function $f$ on $\mathbb{R}^n$ is &lt;em&gt;essentially smooth&lt;/em&gt; if $f$ is strictlt convex on any convex subset of $\text{dom}(\partial f)=\{x\mid \partial f(x)\neq \varnothing\}$.&lt;/p&gt;
&lt;h1 id=&quot;smoothness-and-strictly-convexity&quot;&gt;Smoothness and Strictly Convexity&lt;/h1&gt;
&lt;p&gt;The duality between essential smoothness and esstential strictly convexity can be characterized as follows.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;(Essential Smoothness and Essential Strictly Convexity)&lt;/strong&gt; A closed proper convex function $f$ is esstentially strictly convex if and only if its convex conjugate $f^{\ast}$ is essentially smooth.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;(Subgradient)&lt;/strong&gt; A closed proper convex function $f$ has one-to-one subgradient mappings if and only if $f$ and $f^{\ast}$ are essentially smooth; if and only if $f$ is strictly convex on $\text{int}(\text{dom}(f))$ and is essentially smooth.&lt;/p&gt;
&lt;h1 id=&quot;the-legendre-transformation&quot;&gt;The Legendre Transformation&lt;/h1&gt;
&lt;p&gt;Note that from the definition of convex conjugate
$$
\begin{align*}
f^{\ast}(u) &amp;amp;= \sup\limits_{x\in\mathbb{R}^n} x^{\top}u - f(x)
\end{align*}$$
If $f$ is differentiable (on its domain), we take the derivative and set to zero:
$$u-\nabla f(x)=0.$$
If $\nabla f$ is a one-to-one mapping, then $x=[\nabla f]^{-1}(u)$ obtains the supremum. Thus,
$$f^{\ast}(u) = \langle [\nabla f]^{-1}(u), u \rangle- f([\nabla f]^{-1}(u)),$$
which is called the &lt;em&gt;Legendre conjugate&lt;/em&gt;.&lt;/p&gt;</content><author><name>Jin-Hong Du</name><email>jinhongd@hku.hk</email></author><category term="Optimization" /><summary type="html">This post summarizes differential theory on convex functions, including directional derivatives, subgradients, and Legendre transformation.</summary></entry><entry><title type="html">Duality</title><link href="https://jinhongdu-lab.github.io/posts/2021/10/blog-duality/" rel="alternate" type="text/html" title="Duality" /><published>2021-12-20T00:00:00-08:00</published><updated>2021-12-20T00:00:00-08:00</updated><id>https://jinhongdu-lab.github.io/posts/2021/10/duality</id><content type="html" xml:base="https://jinhongdu-lab.github.io/posts/2021/10/blog-duality/">&lt;p&gt;This post summarizes duality.&lt;/p&gt;
&lt;h1 id=&quot;separation-theorem&quot;&gt;Separation Theorem&lt;/h1&gt;
&lt;h1 id=&quot;convex-conjugates&quot;&gt;Convex Conjugates&lt;/h1&gt;
&lt;h1 id=&quot;primal-dual-formulation&quot;&gt;Primal-Dual Formulation&lt;/h1&gt;</content><author><name>Jin-Hong Du</name><email>jinhongd@hku.hk</email></author><category term="Optimization" /><summary type="html">This post summarizes duality.</summary></entry><entry><title type="html">Convex Sets and Convex Functions</title><link href="https://jinhongdu-lab.github.io/posts/2021/10/blog-convex-set-and-function/" rel="alternate" type="text/html" title="Convex Sets and Convex Functions" /><published>2021-12-17T00:00:00-08:00</published><updated>2021-12-17T00:00:00-08:00</updated><id>https://jinhongdu-lab.github.io/posts/2021/10/convex-set-and-function</id><content type="html" xml:base="https://jinhongdu-lab.github.io/posts/2021/10/blog-convex-set-and-function/">&lt;p&gt;This post summarizes convex sets and convex functions, and their properties.&lt;/p&gt;
&lt;h1 id=&quot;convex-sets&quot;&gt;Convex Sets&lt;/h1&gt;
&lt;h1 id=&quot;convex-functions&quot;&gt;Convex Functions&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;(Convexity)&lt;/strong&gt; A function $f$ is convex if
$$f(tx+(1-t)y)\leq tf(x)+(1-t)f(y),$$
for all $x,y\in dom(f)$ and $t\in(0,1)$.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;(Strict Convexity)&lt;/strong&gt; A function $f$ is strictly convex if
$$f(tx+(1-t)y)&amp;lt; tf(x)+(1-t)f(y),$$
for all $x,y\in dom(f)$ and $t\in(0,1)$.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;(Strong Convexity)&lt;/strong&gt; A function $f$ is $m$-strongly convex if $f(x)-\frac{m}{2}\|x\|_2^2$ is convex.&lt;/p&gt;
&lt;p&gt;Strong convexity implies strict convexity, which implies convexity.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If a convex function has a local minimum $x^{\ast}$, then $x^{\ast}$ is also a global minimum.&lt;/li&gt;
&lt;li&gt;If a strictly convex function has a local/global minimum $x^{\ast}$, then $x^{\ast}$ is the unique global minimum.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A &lt;em&gt;proper convex&lt;/em&gt; function is an extended real-valued convex function with a non-empty domain, that never takes on the value $-\infty$ and also is not identically equal to $+\infty $.&lt;/p&gt;
&lt;h1 id=&quot;convex-functions-over-k&quot;&gt;Convex Functions over $K$&lt;/h1&gt;</content><author><name>Jin-Hong Du</name><email>jinhongd@hku.hk</email></author><category term="Optimization" /><summary type="html">This post summarizes convex sets and convex functions, and their properties.</summary></entry><entry><title type="html">Causal Inference</title><link href="https://jinhongdu-lab.github.io/posts/2021/10/blog-causal-inference/" rel="alternate" type="text/html" title="Causal Inference" /><published>2021-12-07T00:00:00-08:00</published><updated>2021-12-07T00:00:00-08:00</updated><id>https://jinhongdu-lab.github.io/posts/2021/10/causal-inference</id><content type="html" xml:base="https://jinhongdu-lab.github.io/posts/2021/10/blog-causal-inference/">&lt;p&gt;This post summarizes causal inference.&lt;/p&gt;
&lt;h1 id=&quot;the-potential-outcomes-framework&quot;&gt;The Potential Outcomes Framework&lt;/h1&gt;
&lt;p&gt;Suppose we have two random variables $X$ and $Y$, where $Y$ is a binary outcome.
We are interested in determining whether $X$ causes $Y$.
However, for the $i$th unit/sample, we can also observe $Y_i^{obs}$, which is either $Y_i(1)$ or $Y_i(0)$.
We aim to use $(X_i,Y_i^{obs})$&apos;s to estimate some quantities related to the &lt;em&gt;causal effect&lt;/em&gt; of treatment.&lt;/p&gt;
&lt;p&gt;The causal estimands include&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The unit level causal effects $Y_i(1)-Y_i(0)$, $Y_i(1)/Y_i(0)$, and etc.&lt;/li&gt;
&lt;li&gt;The average treatment effect: $\hat{\tau}=\frac{1}{n}\sum\limits_{i=1}^n (Y_i(1)-Y_i(0))$ for estimating $\tau=\mathbb{E}[Y(1)-Y(0)]$.&lt;/li&gt;
&lt;li&gt;The average treatment effect over sub-populations: $\hat{\tau}_S=\frac{1}{|S|}\sum\limits_{i=1}^n (Y_i(1)-Y_i(0))\mathbf{1}\{i\in S\}$.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Suppose that if there is a causal link between a binary treatment $W$ and an outcome $Y$. For a particular unit, if $W_i= 1$ we say that the unit is treated and if $W_i = 0$ then the unit is in the control group.
What we observe is $$Y_i^{obs}=W_iY_i(1)+(1-W_i)Y_i(0).$$
We can estimate the &lt;em&gt;association&lt;/em&gt; $$\alpha=\mathbb{E}[Y(1)\mid W=1]-\mathbb{E}[Y(0)\mid W=0]$$
by an estimator $$\hat{\alpha}=\frac{1}{|T|}\sum\limits_{i\in T}Y_i^{obs}-\frac{1}{|C|}\sum\limits_{i\in C}Y_i^{obs}$$
where $T=\{i:W_i=1\}$ and $C=\{i:W_i=0\}$.&lt;/p&gt;
&lt;p&gt;In general, the association is not equal to the average causal effect, i.e., $\alpha\neq\tau$, which is caused by the selection bias.
However, if we consider &lt;em&gt;randomized controlled trials (RCT)&lt;/em&gt; by enforcing the condition that $$W\perp\!\!\!\!\perp (Y(1),Y(0)),$$
then we have $\alpha=\tau$.&lt;/p&gt;
&lt;h1 id=&quot;confounding&quot;&gt;Confounding&lt;/h1&gt;
&lt;h2 id=&quot;identification-of-tau&quot;&gt;Identification of $\tau$&lt;/h2&gt;
&lt;p&gt;For most studies, we do not have randomly trials and can only have &lt;em&gt;observation data&lt;/em&gt;.
To make causal inference from observational data possible in such case, we need to assume &lt;em&gt;no unmeasured confounding&lt;/em&gt; or &lt;em&gt;no selection on observables&lt;/em&gt; or &lt;em&gt;ignorability&lt;/em&gt;. Formally, we assume $$W\perp\!\!\!\!\perp (Y(1),Y(0))\mid X,$$
where $X$ is some covariate.&lt;/p&gt;
&lt;p&gt;Note that under the previous assumption, we have
$$\begin{align*}
\tau &amp;amp; = \mathbb{E}[Y(1)-Y(0)]\\
&amp;amp;= \mathbb{E}[\mathbb{E}[Y(1)-Y(0)\mid X]]\\
&amp;amp;= \mathbb{E}[\mathbb{E}[Y(1)\mid X,W=1]]-\mathbb{E}[\mathbb{E}[Y(0)\mid X,W=0]]\\
&amp;amp;= \mathbb{E}[\mathbb{E}[Y^{obs}\mid X,W=1]]-\mathbb{E}[\mathbb{E}[Y^{obs}\mid X,W=0]].
\end{align*}$$
Thus, we are able to estimate $\tau$ from the observed data $(X,W,Y^{obs})$ instead of the original data $(X,W,Y(1),Y(0))$.&lt;/p&gt;
&lt;h2 id=&quot;estimation&quot;&gt;Estimation&lt;/h2&gt;
&lt;p&gt;There are two ways to estimate $\tau$ based on such idea.&lt;/p&gt;
&lt;p&gt;The first approach is based on regression estimators $\hat{\mu}_1$ and $\hat{\mu}_0$ of
$$\begin{align*}
\mu_1(x)&amp;amp;= \mathbb{E}[\mathbb{E}[Y^{obs}\mid X=x,W=1]]\\
\mu_0(x)&amp;amp;=\mathbb{E}[\mathbb{E}[Y^{obs}\mid X=x,W=0]].
\end{align*}$$
Then we can compute the plug-in estimator:
$$\hat{\tau}= \frac{1}{n}\sum\limits_{i=1}^n[\hat{\mu}_1(X_i)-\hat{\mu}_0(X_i)].$$
One approximately correct way to think about this is that we are using regression to impute the missing potential outcomes for each individual.&lt;/p&gt;
&lt;p&gt;The second approach is based on &lt;em&gt;Horvitz-Thompson estimator&lt;/em&gt; or the inverse propensity score estimator.
Firstly, we define the &lt;em&gt;propensity score&lt;/em&gt; by $$\pi(x)=\mathbb{P}(W=1\mid X=x),$$
which represents the probability that a unit with covariates x receives treatment. Note that,
$$\begin{align*}
\mathbb{E}[W\mid X=x]&amp;amp;= \pi(x)\\
\mathbb{E}[1-W\mid X=x]&amp;amp;=1-\pi(x).
\end{align*}$$
Then we have
$$\begin{align*}
\tau &amp;amp;= \mathbb{E}[\mathbb{E}[Y(1)-Y(0)\mid X]]\\
&amp;amp;= \mathbb{E}\left[\mathbb{E}\left[\frac{Y(1)W}{\pi(X)}-\frac{Y(0)(1-W)}{1-\pi(X)}\mid X\right]\right]\\
&amp;amp;= \mathbb{E}\left[\mathbb{E}\left[\frac{Y^{obs}W}{\pi(X)}\mid X\right]\right] - \mathbb{E}\left[\mathbb{E}\left[\frac{Y^{obs}(1-W)}{1-\pi(X)}\mid X\right]\right],
\end{align*}$$
which can be estimated as
$$\begin{align*}
\hat{\tau}
&amp;amp;= \frac{1}{n}\sum\limits_{i=1}^n \left[\frac{Y_i^{obs}W_i}{\pi(X_i)}-\frac{Y_i^{obs}(1-W_i)}{1-\pi(X_i)}\right].
\end{align*}$$
In practice, we need to estimate $\pi(x)$ by regression.&lt;/p&gt;
&lt;h1 id=&quot;comments&quot;&gt;Comments&lt;/h1&gt;
&lt;p&gt;We use potential outcomes to describe causality and causal inference coming from the work of Neyman (and later Rubin).
However, there are also other languages.
For example, (causal) directed graphs pioneered by Judea Pearl.
While they focus more on a much harder problem of &lt;em&gt;causal discovery&lt;/em&gt;, which requires even stronger assumptions.&lt;/p&gt;</content><author><name>Jin-Hong Du</name><email>jinhongd@hku.hk</email></author><category term="Statistics" /><summary type="html">This post summarizes causal inference.</summary></entry><entry><title type="html">Nonparametric Regression</title><link href="https://jinhongdu-lab.github.io/posts/2021/10/blog-nonparametric/" rel="alternate" type="text/html" title="Nonparametric Regression" /><published>2021-12-07T00:00:00-08:00</published><updated>2021-12-07T00:00:00-08:00</updated><id>https://jinhongdu-lab.github.io/posts/2021/10/nonparametric</id><content type="html" xml:base="https://jinhongdu-lab.github.io/posts/2021/10/blog-nonparametric/">&lt;p&gt;This post summarizes nonparametric regression.&lt;/p&gt;
&lt;h1 id=&quot;non-parametric-regression&quot;&gt;Non-parametric Regression&lt;/h1&gt;
&lt;p&gt;Assume that we have data $\{(X_1,Y_1),\ldots,(X_n,Y_n)\}$ and our goal is to estimate the regression function $$r(x)=\mathbb{E}[Y\mid X=x].$$
Recall that we can estimate the cdf without distributional assumption by &lt;a href=&quot;https://jinhongdu-lab.github.io/posts/2021/10/blog-uniform-laws/&quot;&gt;Glivenko-Cantelli Theorem&lt;/a&gt;; however, we need &lt;em&gt;smoothness&lt;/em&gt; assumption on $r(x)$ for non-parametric regression.&lt;/p&gt;
&lt;p&gt;For any estimator $\hat{r}$, we define the integrated squared loss by $$L(\hat{r},r)=\int_{\mathcal{X}}[\hat{r}(x)-r(x)]^2\mathrm{d}x,$$
which depends on both $(X_i,y_i)$&apos;s.
The risk is thus given by $$R(\hat{r},r)=\mathbb{E}[L(\hat{r},r)]=\int_{\mathcal{X}}b^2(x)\mathrm{d}x+\int_{\mathcal{X}}v(x)\mathrm{d}x,$$
by switching the integral and expectation, where
$$\begin{align*}
b(x) &amp;amp;= \mathbb{E}[\hat{r}(x)] - r(x)\\
v(x) &amp;amp;= \mathbb{E}[(\hat{r}(x) - r(x))^2].
\end{align*}$$&lt;/p&gt;
&lt;p&gt;Suppose we knew the joint distribution over $(X,Y)$.
Then an alternative measurement of risk can be the prediction error
$$R(\hat{r})=\mathbb{E}[(Y-\hat{r}(X))^2],$$
which is minimized by $r(x)=\mathbb{E}[Y\mid X=x].$&lt;/p&gt;
&lt;h1 id=&quot;kernel-smoothing&quot;&gt;Kernel Smoothing&lt;/h1&gt;
&lt;p&gt;We use the first risk measurement for the following analysis.
We assume that there is only one covariate, while it can be readily generalized to the multivariate case.
The estimator takes the form $$\hat{r}(x)=\sum\limits_{i=1}^nw_i(x)Y_i,$$
where the weights are defined by$$w_i(x)=\frac{K\left(\frac{x-X_i}{h}\right)}{\sum\limits_{j=1}^nK\left(\frac{x-X_j}{h}\right)},$$
$h$ is the bandwidth controlling the amount of smoothing, and $K$ is the kernel.&lt;/p&gt;</content><author><name>Jin-Hong Du</name><email>jinhongd@hku.hk</email></author><category term="Statistics" /><summary type="html">This post summarizes nonparametric regression.</summary></entry></feed>