diff --git a/docs/.vuepress/.cache/markdown/auto-frontmatter.json b/docs/.vuepress/.cache/markdown/auto-frontmatter.json index 88f8abab..14e01ed7 100644 --- a/docs/.vuepress/.cache/markdown/auto-frontmatter.json +++ b/docs/.vuepress/.cache/markdown/auto-frontmatter.json @@ -1 +1 @@ -{"/Users/hughes/docs/WDL_Tools_docs/docs/README.md":"1731032419531.3145","/Users/hughes/docs/WDL_Tools_docs/docs/quickstart.md":"1731032419535.6238","/Users/hughes/docs/WDL_Tools_docs/docs/en/README.md":"1731032419531.4114","/Users/hughes/docs/WDL_Tools_docs/docs/preview/custom-component.example.md":"1731032419535.5134","/Users/hughes/docs/WDL_Tools_docs/docs/preview/markdown.md":"1731032419535.5667","/Users/hughes/docs/WDL_Tools_docs/docs/notes/intruction.md":"1731032419535.3533","/Users/hughes/docs/WDL_Tools_docs/docs/notes/onProgress.md":"1731036333208.258","/Users/hughes/docs/WDL_Tools_docs/docs/en/preview/custom-component.example.md":"1731032419531.734","/Users/hughes/docs/WDL_Tools_docs/docs/en/preview/markdown.md":"1731032419531.8218","/Users/hughes/docs/WDL_Tools_docs/docs/notes/01_10X_Genomics/README.md":"1731032419534.3516","/Users/hughes/docs/WDL_Tools_docs/docs/notes/01_10X_Genomics/scRNA-seq.md":"1731032419534.447","/Users/hughes/docs/WDL_Tools_docs/docs/notes/02_othersNot10XGenomics/README.md":"1731036604199.0923","/Users/hughes/docs/WDL_Tools_docs/docs/notes/03_dataArrangement/README.md":"1731032419534.9148","/Users/hughes/docs/WDL_Tools_docs/docs/notes/04_codeStyle/README.md":"1731032746992.298","/Users/hughes/docs/WDL_Tools_docs/docs/notes/04_codeStyle/meandAI.md":"1731060359253.3975","/Users/hughes/docs/WDL_Tools_docs/docs/notes/demo/README.md":"1731032419535.124","/Users/hughes/docs/WDL_Tools_docs/docs/notes/demo/bar.md":"1731032419535.221","/Users/hughes/docs/WDL_Tools_docs/docs/notes/demo/foo.md":"1731032419535.2754","/Users/hughes/docs/WDL_Tools_docs/docs/en/notes/demo/README.md":"1731032419531.532","/Users/hughes/docs/WDL_Tools_docs/docs/en/notes/demo/bar.md":"1731032419531.608","/Users/hughes/docs/WDL_Tools_docs/docs/en/notes/demo/foo.md":"1731032419531.658"} \ No newline at end of file +{"/Users/hughes/docs/WDL_Tools_docs/docs/README.md":"1731321122041.9927","/Users/hughes/docs/WDL_Tools_docs/docs/quickstart.md":"1731321122043.7888","/Users/hughes/docs/WDL_Tools_docs/docs/en/README.md":"1731321122042.1094","/Users/hughes/docs/WDL_Tools_docs/docs/notes/intruction.md":"1731321122043.505","/Users/hughes/docs/WDL_Tools_docs/docs/notes/onProgress.md":"1731321122043.593","/Users/hughes/docs/WDL_Tools_docs/docs/preview/custom-component.example.md":"1731321122043.6702","/Users/hughes/docs/WDL_Tools_docs/docs/preview/markdown.md":"1731321122043.7256","/Users/hughes/docs/WDL_Tools_docs/docs/en/preview/custom-component.example.md":"1731321122042.415","/Users/hughes/docs/WDL_Tools_docs/docs/en/preview/markdown.md":"1731321122042.4993","/Users/hughes/docs/WDL_Tools_docs/docs/notes/01_10X_Genomics/README.md":"1731321122042.6746","/Users/hughes/docs/WDL_Tools_docs/docs/notes/01_10X_Genomics/scRNA-seq.md":"1731321728191.347","/Users/hughes/docs/WDL_Tools_docs/docs/notes/02_othersNot10XGenomics/README.md":"1731321122042.8682","/Users/hughes/docs/WDL_Tools_docs/docs/notes/03_dataArrangement/README.md":"1731321122042.9434","/Users/hughes/docs/WDL_Tools_docs/docs/notes/04_codeStyle/README.md":"1731321122043.0251","/Users/hughes/docs/WDL_Tools_docs/docs/notes/04_codeStyle/meandAI.md":"1731321122043.2349","/Users/hughes/docs/WDL_Tools_docs/docs/notes/demo/README.md":"1731321122043.332","/Users/hughes/docs/WDL_Tools_docs/docs/notes/demo/bar.md":"1731321122043.3794","/Users/hughes/docs/WDL_Tools_docs/docs/notes/demo/foo.md":"1731321122043.4397","/Users/hughes/docs/WDL_Tools_docs/docs/en/notes/demo/README.md":"1731321122042.2234","/Users/hughes/docs/WDL_Tools_docs/docs/en/notes/demo/bar.md":"1731321122042.287","/Users/hughes/docs/WDL_Tools_docs/docs/en/notes/demo/foo.md":"1731321122042.336"} \ No newline at end of file diff --git a/docs/.vuepress/.cache/markdown/rendered/36c83715 b/docs/.vuepress/.cache/markdown/rendered/36c83715 index 057e19aa..73b5b020 100644 --- a/docs/.vuepress/.cache/markdown/rendered/36c83715 +++ b/docs/.vuepress/.cache/markdown/rendered/36c83715 @@ -1 +1 @@ -{"content":"
加粗:加粗文字
\n斜体: 斜体文字
\n删除文字
内容 标记
\n数学表达式: −(2n−1) ~ 2n−1−1
\n∂ωr∂r(ωyω)=(ωyω){(logy)r+∑i=1rωi(−1)Ir⋯(r−i+1)(logy)ri}
\n19th
\nH2O
\n内容居中
\n内容右对齐
\nTables | \nAre | \nCool | \n
---|---|---|
col 3 is | \nright-aligned | \n$1600 | \n
col 2 is | \ncentered | \n$12 | \n
zebra stripes | \nare neat | \n$1 | \n
\n\n\n\n引用内容
\n引用内容
\n
Badge:
\n图标:
\ndemo wrapper:
\n示例
\n代码:
\nconst a = 1\nconst b = 2\nconst c = a + b\n\nconst obj = {\n toLong: {\n deep: {\n deep: {\n deep: {\n value: 'this is to long text. this is to long text. this is to long text. this is to long text.',\n }\n }\n }\n }\n}
\n\n代码分组:
\nconst a = 1\nconst b = 2\nconst c = a + b
\n\nconst a: number = 1\nconst b: number = 2\nconst c: number = a + b
\n\n代码块高亮:
\nfunction foo() {\n const a = 1\n\n console.log(a)\n\n const b = 2\n const c = 3\n\n console.log(a + b + c)\n console.log(a + b)\n}
\n\n代码块聚焦:
\nfunction foo() {\n const a = 1\n}
\n\nGFM alert:
\n注
\nnote
\n相关信息
\ninfo
\n提示
\ntip
\n注意
\nwarning
\n警告
\ncaution
\n重要
\nimportant
\n代码演示:
\n<h1>Hello Word!</h1>\n<p><span id=\"very\">非常</span>强大!</p>
\n\ndocument.querySelector('#very').addEventListener('click', () => {\n alert('非常强大')\n})
\n\nspan {\n color: red;\n}
\n\n选项卡:
\n内容区块
\n内容区块
\n注意
\n内容区块
\n内容区块
\n脚注:
\n脚注 1 链接[1]。
\n脚注 2 链接[2]。
\n行内的脚注[3] 定义。
\n重复的页脚定义[2:1]。
\n加粗:加粗文字
\n斜体: 斜体文字
\n删除文字
内容 标记
\n数学表达式: −(2n−1) ~ 2n−1−1
\n∂ωr∂r(ωyω)=(ωyω){(logy)r+∑i=1rωi(−1)Ir⋯(r−i+1)(logy)ri}
\n19th
\nH2O
\n内容居中
\n内容右对齐
\nTables | \nAre | \nCool | \n
---|---|---|
col 3 is | \nright-aligned | \n$1600 | \n
col 2 is | \ncentered | \n$12 | \n
zebra stripes | \nare neat | \n$1 | \n
\n\n\n\n引用内容
\n引用内容
\n
Badge:
\n图标:
\ndemo wrapper:
\n示例
\n代码:
\nconst a = 1\nconst b = 2\nconst c = a + b\n\nconst obj = {\n toLong: {\n deep: {\n deep: {\n deep: {\n value: 'this is to long text. this is to long text. this is to long text. this is to long text.',\n }\n }\n }\n }\n}
\n\n代码分组:
\nconst a = 1\nconst b = 2\nconst c = a + b
\n\nconst a: number = 1\nconst b: number = 2\nconst c: number = a + b
\n\n代码块高亮:
\nfunction foo() {\n const a = 1\n\n console.log(a)\n\n const b = 2\n const c = 3\n\n console.log(a + b + c)\n console.log(a + b)\n}
\n\n代码块聚焦:
\nfunction foo() {\n const a = 1\n}
\n\nGFM alert:
\n注
\nnote
\n相关信息
\ninfo
\n提示
\ntip
\n注意
\nwarning
\n警告
\ncaution
\n重要
\nimportant
\n代码演示:
\n<h1>Hello Word!</h1>\n<p><span id=\"very\">非常</span>强大!</p>
\n\ndocument.querySelector('#very').addEventListener('click', () => {\n alert('非常强大')\n})
\n\nspan {\n color: red;\n}
\n\n选项卡:
\n内容区块
\n内容区块
\n注意
\n内容区块
\n内容区块
\n脚注:
\n脚注 1 链接[1]。
\n脚注 2 链接[2]。
\n行内的脚注[3] 定义。
\n重复的页脚定义[2:1]。
\n加粗:加粗文字
\n斜体: 斜体文字
\n删除文字
内容 标记
\n数学表达式: −(2n−1) ~ 2n−1−1
\n∂ωr∂r(ωyω)=(ωyω){(logy)r+∑i=1rωi(−1)Ir⋯(r−i+1)(logy)ri}
\n19th
\nH2O
\n内容居中
\n内容右对齐
\nTables | \nAre | \nCool | \n
---|---|---|
col 3 is | \nright-aligned | \n$1600 | \n
col 2 is | \ncentered | \n$12 | \n
zebra stripes | \nare neat | \n$1 | \n
\n\n\n\n引用内容
\n引用内容
\n
Badge:
\n图标:
\ndemo wrapper:
\n示例
\n代码:
\nconst a = 1\nconst b = 2\nconst c = a + b\n\nconst obj = {\n toLong: {\n deep: {\n deep: {\n deep: {\n value: 'this is to long text. this is to long text. this is to long text. this is to long text.',\n }\n }\n }\n }\n}
\n\n代码分组:
\nconst a = 1\nconst b = 2\nconst c = a + b
\n\nconst a: number = 1\nconst b: number = 2\nconst c: number = a + b
\n\n代码块高亮:
\nfunction foo() {\n const a = 1\n\n console.log(a)\n\n const b = 2\n const c = 3\n\n console.log(a + b + c)\n console.log(a + b)\n}
\n\n代码块聚焦:
\nfunction foo() {\n const a = 1\n}
\n\nGFM alert:
\n注
\nnote
\n相关信息
\ninfo
\n提示
\ntip
\n注意
\nwarning
\n警告
\ncaution
\n重要
\nimportant
\n代码演示:
\n<h1>Hello Word!</h1>\n<p><span id=\"very\">非常</span>强大!</p>
\n\ndocument.querySelector('#very').addEventListener('click', () => {\n alert('非常强大')\n})
\n\nspan {\n color: red;\n}
\n\n选项卡:
\n内容区块
\n内容区块
\n注意
\n内容区块
\n内容区块
\n脚注:
\n脚注 1 链接[1]。
\n脚注 2 链接[2]。
\n行内的脚注[3] 定义。
\n重复的页脚定义[2:1]。
\n非常强大!
\n```\n\n```js\ndocument.querySelector('#very').addEventListener('click', () => {\n alert('非常强大')\n})\n```\n\n```css\nspan {\n color: red;\n}\n```\n\n:::\n\n**选项卡:**\n\n::: tabs\n@tab 标题1\n内容区块\n\n@tab 标题2\n内容区块\n:::\n\n:::: warning\n::: tabs\n@tab 标题1\n内容区块\n\n@tab 标题2\n内容区块\n:::\n::::\n\n**脚注:**\n\n脚注 1 链接[^first]。\n\n脚注 2 链接[^second]。\n\n行内的脚注^[行内脚注文本] 定义。\n\n重复的页脚定义[^second]。\n\n[^first]: 脚注 **可以包含特殊标记**\n\n 也可以由多个段落组成\n\n[^second]: 脚注文字。\n\n## online notebook, based on marimo.app\n\n","excerpt":"","includedFiles":[],"footnotes":{"refs":{":first":0,":second":1},"list":[{"label":"first","count":1},{"label":"second","count":2},{"content":"行内脚注文本","tokens":[{"type":"text","tag":"","attrs":null,"map":null,"nesting":0,"level":0,"children":null,"content":"行内脚注文本","markup":"","info":"","meta":null,"block":false,"hidden":false}]}]},"tasklists":4,"title":"","headers":[{"level":2,"title":"Sorry, we are still on progress.","slug":"sorry-we-are-still-on-progress","link":"#sorry-we-are-still-on-progress","children":[]},{"level":2,"title":"正在更新 Still On Progress","slug":"正在更新-still-on-progress","link":"#正在更新-still-on-progress","children":[]},{"level":2,"title":"视频嵌入","slug":"视频嵌入","link":"#视频嵌入","children":[]},{"level":2,"title":"标题 2","slug":"标题-2","link":"#标题-2","children":[{"level":3,"title":"标题 3","slug":"标题-3","link":"#标题-3","children":[]}]},{"level":2,"title":"online notebook, based on marimo.app","slug":"online-notebook-based-on-marimo-app","link":"#online-notebook-based-on-marimo-app","children":[]}]}} +{"content":"colab 嵌入
\n加粗:加粗文字
\n斜体: 斜体文字
\n删除文字
内容 标记
\n数学表达式: −(2n−1) ~ 2n−1−1
\n∂ωr∂r(ωyω)=(ωyω){(logy)r+∑i=1rωi(−1)Ir⋯(r−i+1)(logy)ri}
\n19th
\nH2O
\n内容居中
\n内容右对齐
\nTables | \nAre | \nCool | \n
---|---|---|
col 3 is | \nright-aligned | \n$1600 | \n
col 2 is | \ncentered | \n$12 | \n
zebra stripes | \nare neat | \n$1 | \n
\n\n\n\n引用内容
\n引用内容
\n
Badge:
\n图标:
\ndemo wrapper:
\n示例
\n代码:
\nconst a = 1\nconst b = 2\nconst c = a + b\n\nconst obj = {\n toLong: {\n deep: {\n deep: {\n deep: {\n value: 'this is to long text. this is to long text. this is to long text. this is to long text.',\n }\n }\n }\n }\n}
\n\n代码分组:
\nconst a = 1\nconst b = 2\nconst c = a + b
\n\nconst a: number = 1\nconst b: number = 2\nconst c: number = a + b
\n\n代码块高亮:
\nfunction foo() {\n const a = 1\n\n console.log(a)\n\n const b = 2\n const c = 3\n\n console.log(a + b + c)\n console.log(a + b)\n}
\n\n代码块聚焦:
\nfunction foo() {\n const a = 1\n}
\n\nGFM alert:
\n注
\nnote
\n相关信息
\ninfo
\n提示
\ntip
\n注意
\nwarning
\n警告
\ncaution
\n重要
\nimportant
\n代码演示:
\n<h1>Hello Word!</h1>\n<p><span id=\"very\">非常</span>强大!</p>
\n\ndocument.querySelector('#very').addEventListener('click', () => {\n alert('非常强大')\n})
\n\nspan {\n color: red;\n}
\n\n选项卡:
\n内容区块
\n内容区块
\n注意
\n内容区块
\n内容区块
\n脚注:
\n脚注 1 链接[1]。
\n脚注 2 链接[2]。
\n行内的脚注[3] 定义。
\n重复的页脚定义[2:1]。
\ncolab 嵌入
\n加粗:加粗文字
\n斜体: 斜体文字
\n删除文字
内容 标记
\n数学表达式: −(2n−1) ~ 2n−1−1
\n∂ωr∂r(ωyω)=(ωyω){(logy)r+∑i=1rωi(−1)Ir⋯(r−i+1)(logy)ri}
\n19th
\nH2O
\n内容居中
\n内容右对齐
\nTables | \nAre | \nCool | \n
---|---|---|
col 3 is | \nright-aligned | \n$1600 | \n
col 2 is | \ncentered | \n$12 | \n
zebra stripes | \nare neat | \n$1 | \n
\n\n\n\n引用内容
\n引用内容
\n
Badge:
\n图标:
\ndemo wrapper:
\n示例
\n代码:
\nconst a = 1\nconst b = 2\nconst c = a + b\n\nconst obj = {\n toLong: {\n deep: {\n deep: {\n deep: {\n value: 'this is to long text. this is to long text. this is to long text. this is to long text.',\n }\n }\n }\n }\n}
\n\n代码分组:
\nconst a = 1\nconst b = 2\nconst c = a + b
\n\nconst a: number = 1\nconst b: number = 2\nconst c: number = a + b
\n\n代码块高亮:
\nfunction foo() {\n const a = 1\n\n console.log(a)\n\n const b = 2\n const c = 3\n\n console.log(a + b + c)\n console.log(a + b)\n}
\n\n代码块聚焦:
\nfunction foo() {\n const a = 1\n}
\n\nGFM alert:
\n注
\nnote
\n相关信息
\ninfo
\n提示
\ntip
\n注意
\nwarning
\n警告
\ncaution
\n重要
\nimportant
\n代码演示:
\n<h1>Hello Word!</h1>\n<p><span id=\"very\">非常</span>强大!</p>
\n\ndocument.querySelector('#very').addEventListener('click', () => {\n alert('非常强大')\n})
\n\nspan {\n color: red;\n}
\n\n选项卡:
\n内容区块
\n内容区块
\n注意
\n内容区块
\n内容区块
\n脚注:
\n脚注 1 链接[1]。
\n脚注 2 链接[2]。
\n行内的脚注[3] 定义。
\n重复的页脚定义[2:1]。
\ncolab 嵌入
\n加粗:加粗文字
\n斜体: 斜体文字
\n删除文字
内容 标记
\n数学表达式: −(2n−1) ~ 2n−1−1
\n∂ωr∂r(ωyω)=(ωyω){(logy)r+∑i=1rωi(−1)Ir⋯(r−i+1)(logy)ri}
\n19th
\nH2O
\n内容居中
\n内容右对齐
\nTables | \nAre | \nCool | \n
---|---|---|
col 3 is | \nright-aligned | \n$1600 | \n
col 2 is | \ncentered | \n$12 | \n
zebra stripes | \nare neat | \n$1 | \n
\n\n\n\n引用内容
\n引用内容
\n
Badge:
\n图标:
\ndemo wrapper:
\n示例
\n代码:
\nconst a = 1\nconst b = 2\nconst c = a + b\n\nconst obj = {\n toLong: {\n deep: {\n deep: {\n deep: {\n value: 'this is to long text. this is to long text. this is to long text. this is to long text.',\n }\n }\n }\n }\n}
\n\n代码分组:
\nconst a = 1\nconst b = 2\nconst c = a + b
\n\nconst a: number = 1\nconst b: number = 2\nconst c: number = a + b
\n\n代码块高亮:
\nfunction foo() {\n const a = 1\n\n console.log(a)\n\n const b = 2\n const c = 3\n\n console.log(a + b + c)\n console.log(a + b)\n}
\n\n代码块聚焦:
\nfunction foo() {\n const a = 1\n}
\n\nGFM alert:
\n注
\nnote
\n相关信息
\ninfo
\n提示
\ntip
\n注意
\nwarning
\n警告
\ncaution
\n重要
\nimportant
\n代码演示:
\n<h1>Hello Word!</h1>\n<p><span id=\"very\">非常</span>强大!</p>
\n\ndocument.querySelector('#very').addEventListener('click', () => {\n alert('非常强大')\n})
\n\nspan {\n color: red;\n}
\n\n选项卡:
\n内容区块
\n内容区块
\n注意
\n内容区块
\n内容区块
\n脚注:
\n脚注 1 链接[1]。
\n脚注 2 链接[2]。
\n行内的脚注[3] 定义。
\n重复的页脚定义[2:1]。
\n非常强大!
\n```\n\n```js\ndocument.querySelector('#very').addEventListener('click', () => {\n alert('非常强大')\n})\n```\n\n```css\nspan {\n color: red;\n}\n```\n\n:::\n\n**选项卡:**\n\n::: tabs\n@tab 标题1\n内容区块\n\n@tab 标题2\n内容区块\n:::\n\n:::: warning\n::: tabs\n@tab 标题1\n内容区块\n\n@tab 标题2\n内容区块\n:::\n::::\n\n**脚注:**\n\n脚注 1 链接[^first]。\n\n脚注 2 链接[^second]。\n\n行内的脚注^[行内脚注文本] 定义。\n\n重复的页脚定义[^second]。\n\n[^first]: 脚注 **可以包含特殊标记**\n\n 也可以由多个段落组成\n\n[^second]: 脚注文字。\n\n## online notebook, based on marimo.app\n\n","excerpt":"","includedFiles":[],"footnotes":{"refs":{":first":0,":second":1},"list":[{"label":"first","count":1},{"label":"second","count":2},{"content":"行内脚注文本","tokens":[{"type":"text","tag":"","attrs":null,"map":null,"nesting":0,"level":0,"children":null,"content":"行内脚注文本","markup":"","info":"","meta":null,"block":false,"hidden":false}]}]},"tasklists":4,"title":"","headers":[{"level":2,"title":"Sorry, we are still on progress.","slug":"sorry-we-are-still-on-progress","link":"#sorry-we-are-still-on-progress","children":[]},{"level":2,"title":"正在更新 Still On Progress","slug":"正在更新-still-on-progress","link":"#正在更新-still-on-progress","children":[]},{"level":2,"title":"视频嵌入","slug":"视频嵌入","link":"#视频嵌入","children":[]},{"level":2,"title":"标题 2","slug":"标题-2","link":"#标题-2","children":[{"level":3,"title":"标题 3","slug":"标题-3","link":"#标题-3","children":[]}]},{"level":2,"title":"online notebook, based on marimo.app","slug":"online-notebook-based-on-marimo-app","link":"#online-notebook-based-on-marimo-app","children":[]}]}} diff --git a/docs/.vuepress/.cache/markdown/rendered/_metadata.json b/docs/.vuepress/.cache/markdown/rendered/_metadata.json index 4001fe9c..d7037486 100644 --- a/docs/.vuepress/.cache/markdown/rendered/_metadata.json +++ b/docs/.vuepress/.cache/markdown/rendered/_metadata.json @@ -1 +1 @@ -{"en/preview/markdown.md":"eaa713d8","preview/markdown.md":"3ef61bf4","README 2.md":"55d7390e","quickstart.md":"ff9a53d0","en/preview/custom-component.example.md":"62eb0e9e","notes/demo/bar.md":"54b40380","notes/demo/foo.md":"533fd271","preview/custom-component.example.md":"172fb5c4","notes/demo/README.md":"5dc994c6","README.md":"195f2454","en/notes/demo/bar.md":"6f119cc2","en/notes/demo/foo.md":"0802c33f","en/README.md":"17e12da5","en/notes/demo/README.md":"28335ead","notes/intruction.md":"0e5cb07e","notes/01_10X_Genomics/scRNA-seq.md":"0e9ca857","notes/onPress.md":"18a21352","notes/onProgress.md":"d6d028e4","notes/01_10X_Genomics/README.md":"30fe9882","notes/demo/README.md 16-48-42-535.md":"5dc994c6","notes/02_othersNot10XGenomics/README.md":"1176fa1e","notes/03_dataArrangement/README.md":"d16d5e5a","notes/04_codeStyle/meandAI.md":"264d2ecc","notes/04_codeStyle/README.md":"709e3728"} +{"en/preview/markdown.md":"eaa713d8","preview/markdown.md":"3ef61bf4","README 2.md":"55d7390e","quickstart.md":"ff9a53d0","en/preview/custom-component.example.md":"62eb0e9e","notes/demo/bar.md":"54b40380","notes/demo/foo.md":"533fd271","preview/custom-component.example.md":"172fb5c4","notes/demo/README.md":"5dc994c6","README.md":"195f2454","en/notes/demo/bar.md":"6f119cc2","en/notes/demo/foo.md":"0802c33f","en/README.md":"17e12da5","en/notes/demo/README.md":"28335ead","notes/intruction.md":"0e5cb07e","notes/01_10X_Genomics/scRNA-seq.md":"2bf09ecf","notes/onPress.md":"18a21352","notes/onProgress.md":"314a6658","notes/01_10X_Genomics/README.md":"30fe9882","notes/demo/README.md 16-48-42-535.md":"5dc994c6","notes/02_othersNot10XGenomics/README.md":"1176fa1e","notes/03_dataArrangement/README.md":"d16d5e5a","notes/04_codeStyle/meandAI.md":"f46c0234","notes/04_codeStyle/README.md":"709e3728"} diff --git a/docs/.vuepress/.cache/markdown/rendered/da1e6afc b/docs/.vuepress/.cache/markdown/rendered/da1e6afc index 6693b9fa..1f8ba6b5 100644 --- a/docs/.vuepress/.cache/markdown/rendered/da1e6afc +++ b/docs/.vuepress/.cache/markdown/rendered/da1e6afc @@ -1 +1 @@ -{"content":"为了便于工作流的可重复性,我们推荐您使用json文件来描述和存档您的实验参数。
\n这里会涉及到BioOS文件管理的相关内容,请参考
在这里,我们假设您已经对平台的使用有了基础的了解,并创建了必要的文件夹。如果还没有,请参考
请注意,我们不要求您对json文件、WDL文件或者云计算有深入的了解,您只需要知道如何使用json文件来描述您的实验参数。我们的目标是您只需要知道如何“复制、粘贴”就能完成您的实验。
\n让我们开始吧!
\n{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": null,\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": null,\n \"cellranger_count_workflow.sample\": null,\n \"cellranger_count_workflow.secondary\": \"False\"\n}
\n\n看起来很复杂,但没关系。仔细观察,您会发现,这个json文件的部分参数已经自动设置好了,在大部分情况下,您只需要依次填写您自己的参数即可。
\n(markdown格式 引用 可折叠 或者 展开上标引用)注释:作为快速上手教程,我们不对具体的参数做出解释,具体的参数的解释请参考10X Genomics官方文档,在支持文档,我们也会对一些关键参数做出解释。
\n这里我们给出了填写示例:
\n\n\n注意这几个存在内容新增的部分
\n
{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": [ \n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_I1_001.fastq.gz\",\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R1_001.fastq.gz\",\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R2_001.fastq.gz\"\n ],\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": \"ERR8048237\",\n \"cellranger_count_workflow.sample\": \"5891STDY8062334\",\n \"cellranger_count_workflow.secondary\": \"False\"\n}
\n\n是的,就是这么简单。我们添加了文件路径,并填写了run_id和sample。这和您在本地计算的参数填写逻辑是一样的。我们已经准备好了,现在就提交任务吧!
\n让我们回到BioOS平台,来到我们的cellrangerTest页面。试试看,找到页面上的"运行参数"选项卡>输入参数>"上传JSON文件",将您的json文件上传。
\n然后,点击页面上的绿色按钮"开始分析",等待任务完成。
\n任务完成后,您可以在分析历史中看到您的任务。点击任务名称,进入任务详情页面。在任务详情页面,您可以查看/下载结果。
\n点击"查看",让我们来看看结果吧!所有的结果文件都会列出在这里,除了结果之外,也包括运行日志等文件,这取决于WDL文件的具体设置。
\n# 在本例中,你的文件结构是这个样子:\n全部文件/analysis/$投递任务ID/$WDL_Task_ID/$workflow标识ID/call-$WDL_Task_ID/\n├── execution\n│ ├── PRJNA693201_dlst000564_SRR13482541\n│ │ └── outs\n│ │ ├── PRJNA693201_dlst000564_SRR13482541_filtered_feature_bc_matrix.h5ad\n│ │ ├── metrics_summary.csv\n│ │ ├── possorted_genome_bam.bam\n│ │ └── web_summary.html\n│ ├── PRJNA693201_dlst000564_SRR13482541_outs.tar.gz\n│ ├── log # cromwell 日志文件\n│ ├── rc # cromwell 运行时文件\n│ ├── script # cromwell 脚本文件\n│ ├── stderr # cromwell 标准错误文件\n│ └── stdout # cromwell 标准输出文件
\n\n\n\n我们在这里展示的是一个多样本的分析结果(如果您按照上图的方法点击查看结果),所以您会看到多个样本的结果文件夹。让我们逐级打开文件夹,找到我们需要的文件。所有的日志以及结果文件都会列出在这里。
\n
在这个示例中,我们需要的文件在 "outs" 文件夹中,让我们逐渐深入文件夹,找到我们需要的文件。
\n我们需要这里的 $ID_filtered_feature_bc_matrix.h5ad 文件,让我们点击下载。
\n🎊Bravo!🎊 到此为止,您已经掌握了BioOS的基本使用方法,并成功完成了一次10X Genomics scRNA-seq的分析。👏👏👏
\n🤔好,那么好,这时候可能就会有人问了,如果我们有很多数据,也要像这样一个一个点击吗?
\n\n\n非常好的问题!当你尝试把一件简单的事情重复做上一万遍的时候,其复杂度将会指数增加📈。
\n
当然不是,我们在这里只展示了BioOS的冰山一角,BioOS的真正能力将在您尝试构建数据模型/实体之后展现。下面,让我们从一个稍微复杂的例子开始,一步一步的学习如何调度BioOS强大的计算能力。
\n","env":{"base":"/WDL_Tools_docs/","filePath":"/Users/hughes/docs/WDL_Tools_docs/docs/notes/01_10X_Genomics/scRNA-seq.md","filePathRelative":"notes/01_10X_Genomics/scRNA-seq.md","frontmatter":{"title":"10X Genomics scRNA-seq 数据分析","createTime":"2024/10/30 11:20:18","permalink":"/01_10X_Genomics/scRNA-seq/"},"sfcBlocks":{"template":{"type":"template","content":"为了便于工作流的可重复性,我们推荐您使用json文件来描述和存档您的实验参数。
\n这里会涉及到BioOS文件管理的相关内容,请参考
在这里,我们假设您已经对平台的使用有了基础的了解,并创建了必要的文件夹。如果还没有,请参考
请注意,我们不要求您对json文件、WDL文件或者云计算有深入的了解,您只需要知道如何使用json文件来描述您的实验参数。我们的目标是您只需要知道如何“复制、粘贴”就能完成您的实验。
\n让我们开始吧!
\n{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": null,\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": null,\n \"cellranger_count_workflow.sample\": null,\n \"cellranger_count_workflow.secondary\": \"False\"\n}
\n\n看起来很复杂,但没关系。仔细观察,您会发现,这个json文件的部分参数已经自动设置好了,在大部分情况下,您只需要依次填写您自己的参数即可。
\n(markdown格式 引用 可折叠 或者 展开上标引用)注释:作为快速上手教程,我们不对具体的参数做出解释,具体的参数的解释请参考10X Genomics官方文档,在支持文档,我们也会对一些关键参数做出解释。
\n这里我们给出了填写示例:
\n\n\n注意这几个存在内容新增的部分
\n
{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": [ \n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_I1_001.fastq.gz\",\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R1_001.fastq.gz\",\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R2_001.fastq.gz\"\n ],\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": \"ERR8048237\",\n \"cellranger_count_workflow.sample\": \"5891STDY8062334\",\n \"cellranger_count_workflow.secondary\": \"False\"\n}
\n\n是的,就是这么简单。我们添加了文件路径,并填写了run_id和sample。这和您在本地计算的参数填写逻辑是一样的。我们已经准备好了,现在就提交任务吧!
\n让我们回到BioOS平台,来到我们的cellrangerTest页面。试试看,找到页面上的"运行参数"选项卡>输入参数>"上传JSON文件",将您的json文件上传。
\n然后,点击页面上的绿色按钮"开始分析",等待任务完成。
\n任务完成后,您可以在分析历史中看到您的任务。点击任务名称,进入任务详情页面。在任务详情页面,您可以查看/下载结果。
\n点击"查看",让我们来看看结果吧!所有的结果文件都会列出在这里,除了结果之外,也包括运行日志等文件,这取决于WDL文件的具体设置。
\n# 在本例中,你的文件结构是这个样子:\n全部文件/analysis/$投递任务ID/$WDL_Task_ID/$workflow标识ID/call-$WDL_Task_ID/\n├── execution\n│ ├── PRJNA693201_dlst000564_SRR13482541\n│ │ └── outs\n│ │ ├── PRJNA693201_dlst000564_SRR13482541_filtered_feature_bc_matrix.h5ad\n│ │ ├── metrics_summary.csv\n│ │ ├── possorted_genome_bam.bam\n│ │ └── web_summary.html\n│ ├── PRJNA693201_dlst000564_SRR13482541_outs.tar.gz\n│ ├── log # cromwell 日志文件\n│ ├── rc # cromwell 运行时文件\n│ ├── script # cromwell 脚本文件\n│ ├── stderr # cromwell 标准错误文件\n│ └── stdout # cromwell 标准输出文件
\n\n\n\n我们在这里展示的是一个多样本的分析结果(如果您按照上图的方法点击查看结果),所以您会看到多个样本的结果文件夹。让我们逐级打开文件夹,找到我们需要的文件。所有的日志以及结果文件都会列出在这里。
\n
在这个示例中,我们需要的文件在 "outs" 文件夹中,让我们逐渐深入文件夹,找到我们需要的文件。
\n我们需要这里的 $ID_filtered_feature_bc_matrix.h5ad 文件,让我们点击下载。
\n🎊Bravo!🎊 到此为止,您已经掌握了BioOS的基本使用方法,并成功完成了一次10X Genomics scRNA-seq的分析。👏👏👏
\n🤔好,那么好,这时候可能就会有人问了,如果我们有很多数据,也要像这样一个一个点击吗?
\n\n\n非常好的问题!当你尝试把一件简单的事情重复做上一万遍的时候,其复杂度将会指数增加📈。
\n
当然不是,我们在这里只展示了BioOS的冰山一角,BioOS的真正能力将在您尝试构建数据模型/实体之后展现。下面,让我们从一个稍微复杂的例子开始,一步一步的学习如何调度BioOS强大的计算能力。
\n为了便于工作流的可重复性,我们推荐您使用json文件来描述和存档您的实验参数。
\n这里会涉及到BioOS文件管理的相关内容,请参考
在这里,我们假设您已经对平台的使用有了基础的了解,并创建了必要的文件夹。如果还没有,请参考
请注意,我们不要求您对json文件、WDL文件或者云计算有深入的了解,您只需要知道如何使用json文件来描述您的实验参数。我们的目标是您只需要知道如何“复制、粘贴”就能完成您的实验。
\n让我们开始吧!
\n{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": null,\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": null,\n \"cellranger_count_workflow.sample\": null,\n \"cellranger_count_workflow.secondary\": \"False\"\n}
\n\n看起来很复杂,但没关系。仔细观察,您会发现,这个json文件的部分参数已经自动设置好了,在大部分情况下,您只需要依次填写您自己的参数即可。
\n(markdown格式 引用 可折叠 或者 展开上标引用)注释:作为快速上手教程,我们不对具体的参数做出解释,具体的参数的解释请参考10X Genomics官方文档,在支持文档,我们也会对一些关键参数做出解释。
\n这里我们给出了填写示例:
\n\n\n注意这几个存在内容新增的部分
\n
{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": [ \n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_I1_001.fastq.gz\",\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R1_001.fastq.gz\",\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R2_001.fastq.gz\"\n ],\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": \"ERR8048237\",\n \"cellranger_count_workflow.sample\": \"5891STDY8062334\",\n \"cellranger_count_workflow.secondary\": \"False\"\n}
\n\n是的,就是这么简单。我们添加了文件路径,并填写了run_id和sample。这和您在本地计算的参数填写逻辑是一样的。我们已经准备好了,现在就提交任务吧!
\n让我们回到BioOS平台,来到我们的cellrangerTest页面。试试看,找到页面上的"运行参数"选项卡>输入参数>"上传JSON文件",将您的json文件上传。
\n然后,点击页面上的绿色按钮"开始分析",等待任务完成。
\n任务完成后,您可以在分析历史中看到您的任务。点击任务名称,进入任务详情页面。在任务详情页面,您可以查看/下载结果。
\n点击"查看",让我们来看看结果吧!所有的结果文件都会列出在这里,除了结果之外,也包括运行日志等文件,这取决于WDL文件的具体设置。
\n# 在本例中,你的文件结构是这个样子:\n全部文件/analysis/$投递任务ID/$WDL_Task_ID/$workflow标识ID/call-$WDL_Task_ID/\n├── execution\n│ ├── PRJNA693201_dlst000564_SRR13482541\n│ │ └── outs\n│ │ ├── PRJNA693201_dlst000564_SRR13482541_filtered_feature_bc_matrix.h5ad\n│ │ ├── metrics_summary.csv\n│ │ ├── possorted_genome_bam.bam\n│ │ └── web_summary.html\n│ ├── PRJNA693201_dlst000564_SRR13482541_outs.tar.gz\n│ ├── log # cromwell 日志文件\n│ ├── rc # cromwell 运行时文件\n│ ├── script # cromwell 脚本文件\n│ ├── stderr # cromwell 标准错误文件\n│ └── stdout # cromwell 标准输出文件
\n\n\n\n我们在这里展示的是一个多样本的分析结果(如果您按照上图的方法点击查看结果),所以您会看到多个样本的结果文件夹。让我们逐级打开文件夹,找到我们需要的文件。所有的日志以及结果文件都会列出在这里。
\n
在这个示例中,我们需要的文件在 "outs" 文件夹中,让我们逐渐深入文件夹,找到我们需要的文件。
\n我们需要这里的 $ID_filtered_feature_bc_matrix.h5ad 文件,让我们点击下载。
\n🎊Bravo!🎊 到此为止,您已经掌握了BioOS的基本使用方法,并成功完成了一次10X Genomics scRNA-seq的分析。👏👏👏
\n🤔好,那么好,这时候可能就会有人问了,如果我们有很多数据,也要像这样一个一个点击吗?
\n\n\n非常好的问题!当你尝试把一件简单的事情重复做上一万遍的时候,其复杂度将会指数增加📈。
\n
当然不是,我们在这里只展示了BioOS的冰山一角,BioOS的真正能力将在您尝试构建数据模型/实体之后展现。下面,让我们从一个稍微复杂的例子开始,一步一步的学习如何调度BioOS强大的计算能力。
\n","tagOpen":"","tagClose":""},"script":null,"scriptSetup":null,"scripts":[],"styles":[],"customBlocks":[]},"content":"## 10X Genomics scRNA-seq\n\n为了便于工作流的可重复性,我们推荐您使用json文件来描述和存档您的实验参数。\n\n## 写在前面\n\n这里会涉及到BioOS文件管理的相关内容,请参考[BioOS文件管理](../BioOS/README.md)\n\n在这里,我们假设您已经对平台的使用有了基础的了解,并创建了必要的文件夹。如果还没有,请参考[动手学BioOS计算](../BioOS/README.md)\n\n请注意,我们不要求您对json文件、WDL文件或者云计算有深入的了解,您只需要知道如何使用json文件来描述您的实验参数。我们的目标是您只需要知道如何“复制、粘贴”就能完成您的实验。\n\n让我们开始吧!\n\n### 对于一个典型的10X Genomics scRNA-seq实验,我们推荐使用如下的json文件:\n\n```json\n{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": null,\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": null,\n \"cellranger_count_workflow.sample\": null,\n \"cellranger_count_workflow.secondary\": \"False\"\n}\n```\n\n看起来很复杂,但没关系。仔细观察,您会发现,这个json文件的部分参数已经自动设置好了,在大部分情况下,您只需要依次填写您自己的参数即可。\n\n(markdown格式 引用 可折叠 或者 展开上标引用)注释:作为快速上手教程,我们不对具体的参数做出解释,具体的参数的解释请参考[10X Genomics官方文档](https://support.10xgenomics.com/single-cell-gene-expression/software/pipelines/latest/using/count),在支持文档,我们也会对一些关键参数做出解释。\n\n这里我们给出了填写示例:\n> **注意这几个存在内容新增的部分**\n\n```json\n{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": [ \n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_I1_001.fastq.gz\", // [!code ++]\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R1_001.fastq.gz\", // [!code ++]\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R2_001.fastq.gz\" // [!code ++]\n ],\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": \"ERR8048237\", // [!code ++]\n \"cellranger_count_workflow.sample\": \"5891STDY8062334\", // [!code ++]\n \"cellranger_count_workflow.secondary\": \"False\"\n}\n```\n\n是的,就是这么简单。我们添加了文件路径,并填写了run_id和sample。这和您在本地计算的参数填写逻辑是一样的。我们已经准备好了,现在就提交任务吧!\n\n### 提交任务\n\n让我们回到BioOS平台,来到我们的cellrangerTest页面。试试看,找到页面上的\"运行参数\"选项卡>输入参数>\"上传JSON文件\",将您的json文件上传。\n\n然后,点击页面上的绿色按钮\"开始分析\",等待任务完成。\n\n\n为了便于工作流的可重复性,我们推荐您使用json文件来描述和存档您的实验参数。
\n这里会涉及到BioOS文件管理的相关内容,请参考
在这里,我们假设您已经对平台的使用有了基础的了解,并创建了必要的文件夹。如果还没有,请参考
请注意,我们不要求您对json文件、WDL文件或者云计算有深入的了解,您只需要知道如何使用json文件来描述您的实验参数。我们的目标是您只需要知道如何“复制、粘贴”就能完成您的实验。
\n让我们开始吧!
\n{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": null,\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": null,\n \"cellranger_count_workflow.sample\": null,\n \"cellranger_count_workflow.secondary\": \"False\"\n}
\n\n看起来很复杂,但没关系。仔细观察,您会发现,这个json文件的部分参数已经自动设置好了,在大部分情况下,您只需要依次填写您自己的参数即可。
\n(markdown格式 引用 可折叠 或者 展开上标引用)注释:作为快速上手教程,我们不对具体的参数做出解释,具体的参数的解释请参考10X Genomics官方文档,在支持文档,我们也会对一些关键参数做出解释。
\n这里我们给出了填写示例:
\n\n\n注意这几个存在内容新增的部分
\n
{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": [ \n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_I1_001.fastq.gz\",\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R1_001.fastq.gz\",\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R2_001.fastq.gz\"\n ],\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": \"ERR8048237\",\n \"cellranger_count_workflow.sample\": \"5891STDY8062334\",\n \"cellranger_count_workflow.secondary\": \"False\"\n}
\n\n是的,就是这么简单。我们添加了文件路径,并填写了run_id和sample。这和您在本地计算的参数填写逻辑是一样的。我们已经准备好了,现在就提交任务吧!
\n让我们回到BioOS平台,来到我们的cellrangerTest页面。试试看,找到页面上的"运行参数"选项卡>输入参数>"上传JSON文件",将您的json文件上传。
\n然后,点击页面上的绿色按钮"开始分析",等待任务完成。
\n\n任务完成后,您可以在分析历史中看到您的任务。点击任务名称,进入任务详情页面。在任务详情页面,您可以查看/下载结果。
\n点击"查看",让我们来看看结果吧!所有的结果文件都会列出在这里,除了结果之外,也包括运行日志等文件,这取决于WDL文件的具体设置。
\n# 在本例中,你的文件结构是这个样子:\n全部文件/analysis/$投递任务ID/$WDL_Task_ID/$workflow标识ID/call-$WDL_Task_ID/\n├── execution\n│ ├── PRJNA693201_dlst000564_SRR13482541\n│ │ └── outs\n│ │ ├── PRJNA693201_dlst000564_SRR13482541_filtered_feature_bc_matrix.h5ad\n│ │ ├── metrics_summary.csv\n│ │ ├── possorted_genome_bam.bam\n│ │ └── web_summary.html\n│ ├── PRJNA693201_dlst000564_SRR13482541_outs.tar.gz\n│ ├── log # cromwell 日志文件\n│ ├── rc # cromwell 运行时文件\n│ ├── script # cromwell 脚本文件\n│ ├── stderr # cromwell 标准错误文件\n│ └── stdout # cromwell 标准输出文件
\n\n\n\n我们在这里展示的是一个多样本的分析结果(如果您按照上图的方法点击查看结果),所以您会看到多个样本的结果文件夹。让我们逐级打开文件夹,找到我们需要的文件。所有的日志以及结果文件都会列出在这里。
\n
在这个示例中,我们需要的文件在 "outs" 文件夹中,让我们逐渐深入文件夹,找到我们需要的文件。
\n我们需要这里的 $ID_filtered_feature_bc_matrix.h5ad 文件,让我们点击下载。
\n🎊Bravo!🎊 到此为止,您已经掌握了BioOS的基本使用方法,并成功完成了一次10X Genomics scRNA-seq的分析。👏👏👏
\n🤔好,那么好,这时候可能就会有人问了,如果我们有很多数据,也要像这样一个一个点击吗?
\n\n\n非常好的问题!当你尝试把一件简单的事情重复做上一万遍的时候,其复杂度将会指数增加📈。
\n
当然不是,我们在这里只展示了BioOS的冰山一角,BioOS的真正能力将在您尝试构建数据模型/实体之后展现。下面,让我们从一个稍微复杂的例子开始,一步一步的学习如何调度BioOS强大的计算能力。
\n","env":{"base":"/","filePath":"/Users/hughes/docs/WDL_Tools_docs/docs/notes/01_10X_Genomics/scRNA-seq.md","filePathRelative":"notes/01_10X_Genomics/scRNA-seq.md","frontmatter":{"title":"10X Genomics scRNA-seq 数据分析","createTime":"2024/10/30 11:20:18","permalink":"/01_10X_Genomics/scRNA-seq/"},"sfcBlocks":{"template":{"type":"template","content":"为了便于工作流的可重复性,我们推荐您使用json文件来描述和存档您的实验参数。
\n这里会涉及到BioOS文件管理的相关内容,请参考
在这里,我们假设您已经对平台的使用有了基础的了解,并创建了必要的文件夹。如果还没有,请参考
请注意,我们不要求您对json文件、WDL文件或者云计算有深入的了解,您只需要知道如何使用json文件来描述您的实验参数。我们的目标是您只需要知道如何“复制、粘贴”就能完成您的实验。
\n让我们开始吧!
\n{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": null,\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": null,\n \"cellranger_count_workflow.sample\": null,\n \"cellranger_count_workflow.secondary\": \"False\"\n}
\n\n看起来很复杂,但没关系。仔细观察,您会发现,这个json文件的部分参数已经自动设置好了,在大部分情况下,您只需要依次填写您自己的参数即可。
\n(markdown格式 引用 可折叠 或者 展开上标引用)注释:作为快速上手教程,我们不对具体的参数做出解释,具体的参数的解释请参考10X Genomics官方文档,在支持文档,我们也会对一些关键参数做出解释。
\n这里我们给出了填写示例:
\n\n\n注意这几个存在内容新增的部分
\n
{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": [ \n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_I1_001.fastq.gz\",\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R1_001.fastq.gz\",\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R2_001.fastq.gz\"\n ],\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": \"ERR8048237\",\n \"cellranger_count_workflow.sample\": \"5891STDY8062334\",\n \"cellranger_count_workflow.secondary\": \"False\"\n}
\n\n是的,就是这么简单。我们添加了文件路径,并填写了run_id和sample。这和您在本地计算的参数填写逻辑是一样的。我们已经准备好了,现在就提交任务吧!
\n让我们回到BioOS平台,来到我们的cellrangerTest页面。试试看,找到页面上的"运行参数"选项卡>输入参数>"上传JSON文件",将您的json文件上传。
\n然后,点击页面上的绿色按钮"开始分析",等待任务完成。
\n\n任务完成后,您可以在分析历史中看到您的任务。点击任务名称,进入任务详情页面。在任务详情页面,您可以查看/下载结果。
\n点击"查看",让我们来看看结果吧!所有的结果文件都会列出在这里,除了结果之外,也包括运行日志等文件,这取决于WDL文件的具体设置。
\n# 在本例中,你的文件结构是这个样子:\n全部文件/analysis/$投递任务ID/$WDL_Task_ID/$workflow标识ID/call-$WDL_Task_ID/\n├── execution\n│ ├── PRJNA693201_dlst000564_SRR13482541\n│ │ └── outs\n│ │ ├── PRJNA693201_dlst000564_SRR13482541_filtered_feature_bc_matrix.h5ad\n│ │ ├── metrics_summary.csv\n│ │ ├── possorted_genome_bam.bam\n│ │ └── web_summary.html\n│ ├── PRJNA693201_dlst000564_SRR13482541_outs.tar.gz\n│ ├── log # cromwell 日志文件\n│ ├── rc # cromwell 运行时文件\n│ ├── script # cromwell 脚本文件\n│ ├── stderr # cromwell 标准错误文件\n│ └── stdout # cromwell 标准输出文件
\n\n\n\n我们在这里展示的是一个多样本的分析结果(如果您按照上图的方法点击查看结果),所以您会看到多个样本的结果文件夹。让我们逐级打开文件夹,找到我们需要的文件。所有的日志以及结果文件都会列出在这里。
\n
在这个示例中,我们需要的文件在 "outs" 文件夹中,让我们逐渐深入文件夹,找到我们需要的文件。
\n我们需要这里的 $ID_filtered_feature_bc_matrix.h5ad 文件,让我们点击下载。
\n🎊Bravo!🎊 到此为止,您已经掌握了BioOS的基本使用方法,并成功完成了一次10X Genomics scRNA-seq的分析。👏👏👏
\n🤔好,那么好,这时候可能就会有人问了,如果我们有很多数据,也要像这样一个一个点击吗?
\n\n\n非常好的问题!当你尝试把一件简单的事情重复做上一万遍的时候,其复杂度将会指数增加📈。
\n
当然不是,我们在这里只展示了BioOS的冰山一角,BioOS的真正能力将在您尝试构建数据模型/实体之后展现。下面,让我们从一个稍微复杂的例子开始,一步一步的学习如何调度BioOS强大的计算能力。
\n为了便于工作流的可重复性,我们推荐您使用json文件来描述和存档您的实验参数。
\n这里会涉及到BioOS文件管理的相关内容,请参考
在这里,我们假设您已经对平台的使用有了基础的了解,并创建了必要的文件夹。如果还没有,请参考
请注意,我们不要求您对json文件、WDL文件或者云计算有深入的了解,您只需要知道如何使用json文件来描述您的实验参数。我们的目标是您只需要知道如何“复制、粘贴”就能完成您的实验。
\n让我们开始吧!
\n{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": null,\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": null,\n \"cellranger_count_workflow.sample\": null,\n \"cellranger_count_workflow.secondary\": \"False\"\n}
\n\n看起来很复杂,但没关系。仔细观察,您会发现,这个json文件的部分参数已经自动设置好了,在大部分情况下,您只需要依次填写您自己的参数即可。
\n(markdown格式 引用 可折叠 或者 展开上标引用)注释:作为快速上手教程,我们不对具体的参数做出解释,具体的参数的解释请参考10X Genomics官方文档,在支持文档,我们也会对一些关键参数做出解释。
\n这里我们给出了填写示例:
\n\n\n注意这几个存在内容新增的部分
\n
{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": [ \n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_I1_001.fastq.gz\",\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R1_001.fastq.gz\",\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R2_001.fastq.gz\"\n ],\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": \"ERR8048237\",\n \"cellranger_count_workflow.sample\": \"5891STDY8062334\",\n \"cellranger_count_workflow.secondary\": \"False\"\n}
\n\n是的,就是这么简单。我们添加了文件路径,并填写了run_id和sample。这和您在本地计算的参数填写逻辑是一样的。我们已经准备好了,现在就提交任务吧!
\n让我们回到BioOS平台,来到我们的cellrangerTest页面。试试看,找到页面上的"运行参数"选项卡>输入参数>"上传JSON文件",将您的json文件上传。
\n然后,点击页面上的绿色按钮"开始分析",等待任务完成。
\n\n任务完成后,您可以在分析历史中看到您的任务。点击任务名称,进入任务详情页面。在任务详情页面,您可以查看/下载结果。
\n点击"查看",让我们来看看结果吧!所有的结果文件都会列出在这里,除了结果之外,也包括运行日志等文件,这取决于WDL文件的具体设置。
\n# 在本例中,你的文件结构是这个样子:\n全部文件/analysis/$投递任务ID/$WDL_Task_ID/$workflow标识ID/call-$WDL_Task_ID/\n├── execution\n│ ├── PRJNA693201_dlst000564_SRR13482541\n│ │ └── outs\n│ │ ├── PRJNA693201_dlst000564_SRR13482541_filtered_feature_bc_matrix.h5ad\n│ │ ├── metrics_summary.csv\n│ │ ├── possorted_genome_bam.bam\n│ │ └── web_summary.html\n│ ├── PRJNA693201_dlst000564_SRR13482541_outs.tar.gz\n│ ├── log # cromwell 日志文件\n│ ├── rc # cromwell 运行时文件\n│ ├── script # cromwell 脚本文件\n│ ├── stderr # cromwell 标准错误文件\n│ └── stdout # cromwell 标准输出文件
\n\n\n\n我们在这里展示的是一个多样本的分析结果(如果您按照上图的方法点击查看结果),所以您会看到多个样本的结果文件夹。让我们逐级打开文件夹,找到我们需要的文件。所有的日志以及结果文件都会列出在这里。
\n
在这个示例中,我们需要的文件在 "outs" 文件夹中,让我们逐渐深入文件夹,找到我们需要的文件。
\n我们需要这里的 $ID_filtered_feature_bc_matrix.h5ad 文件,让我们点击下载。
\n🎊Bravo!🎊 到此为止,您已经掌握了BioOS的基本使用方法,并成功完成了一次10X Genomics scRNA-seq的分析。👏👏👏
\n🤔好,那么好,这时候可能就会有人问了,如果我们有很多数据,也要像这样一个一个点击吗?
\n\n\n非常好的问题!当你尝试把一件简单的事情重复做上一万遍的时候,其复杂度将会指数增加📈。
\n
当然不是,我们在这里只展示了BioOS的冰山一角,BioOS的真正能力将在您尝试构建数据模型/实体之后展现。下面,让我们从一个稍微复杂的例子开始,一步一步的学习如何调度BioOS强大的计算能力。
\n","tagOpen":"","tagClose":""},"script":null,"scriptSetup":null,"scripts":[],"styles":[],"customBlocks":[]},"content":"## 10X Genomics scRNA-seq\n\n为了便于工作流的可重复性,我们推荐您使用json文件来描述和存档您的实验参数。\n\n## 写在前面\n\n这里会涉及到BioOS文件管理的相关内容,请参考[BioOS文件管理](../BioOS/README.md)\n\n在这里,我们假设您已经对平台的使用有了基础的了解,并创建了必要的文件夹。如果还没有,请参考[动手学BioOS计算](../BioOS/README.md)\n\n请注意,我们不要求您对json文件、WDL文件或者云计算有深入的了解,您只需要知道如何使用json文件来描述您的实验参数。我们的目标是您只需要知道如何“复制、粘贴”就能完成您的实验。\n\n让我们开始吧!\n\n### 对于一个典型的10X Genomics scRNA-seq实验,我们推荐使用如下的json文件:\n\n```json\n{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": null,\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": null,\n \"cellranger_count_workflow.sample\": null,\n \"cellranger_count_workflow.secondary\": \"False\"\n}\n```\n\n看起来很复杂,但没关系。仔细观察,您会发现,这个json文件的部分参数已经自动设置好了,在大部分情况下,您只需要依次填写您自己的参数即可。\n\n(markdown格式 引用 可折叠 或者 展开上标引用)注释:作为快速上手教程,我们不对具体的参数做出解释,具体的参数的解释请参考[10X Genomics官方文档](https://support.10xgenomics.com/single-cell-gene-expression/software/pipelines/latest/using/count),在支持文档,我们也会对一些关键参数做出解释。\n\n这里我们给出了填写示例:\n> **注意这几个存在内容新增的部分**\n\n```json\n{\n \"cellranger_count_workflow.chemistry\": \"auto\",\n \"cellranger_count_workflow.cpu\": 32,\n \"cellranger_count_workflow.disk_space\": \"300 GB\",\n \"cellranger_count_workflow.fastq_file_paths\": [ \n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_I1_001.fastq.gz\", // [!code ++]\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R1_001.fastq.gz\", // [!code ++]\n \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/ERR8048237/5891STDY8062334_S1_L001_R2_001.fastq.gz\" // [!code ++]\n ],\n \"cellranger_count_workflow.memory\": \"225 GB\",\n \"cellranger_count_workflow.no_bam\": \"False\",\n \"cellranger_count_workflow.reference_genome_tar_gz\": \"s3://bioos-wcnjupodeig44rr6t02v0/Example_10X_data/RAW/refdata-cellranger-GRCh38-3.0.0.tar.gz\",\n \"cellranger_count_workflow.run_id\": \"ERR8048237\", // [!code ++]\n \"cellranger_count_workflow.sample\": \"5891STDY8062334\", // [!code ++]\n \"cellranger_count_workflow.secondary\": \"False\"\n}\n```\n\n是的,就是这么简单。我们添加了文件路径,并填写了run_id和sample。这和您在本地计算的参数填写逻辑是一样的。我们已经准备好了,现在就提交任务吧!\n\n### 提交任务\n\n让我们回到BioOS平台,来到我们的cellrangerTest页面。试试看,找到页面上的\"运行参数\"选项卡>输入参数>\"上传JSON文件\",将您的json文件上传。\n\n然后,点击页面上的绿色按钮\"开始分析\",等待任务完成。\n\n![图片](./scfig1_gif.gif)\n\n1. 复制对GPT输入代码风格化的要求
\n--->>> 2. 编写包含你所有的要求和想法的伪代码
\n--------->>> 3. 拆分伪代码,分模块实现
\n\n\n本文通过几个例子展示了用GPT敲代码的几个模式,您需要确保您的键盘具有Ctrl键、C键、V键。
\n
\n\n受文本长度限制,本文尽量不对任何内容的驱动原理做出解释。
\n
注
\n重要
\nAI放大了人类的能力边界,但社会生活的主体依然是自然人。
\n\n\n跟我复制
\n
\n\n如果你有一些类似于“整洁代码”的偏好,或者你有明确的编程习惯,请在进行代码产出时,明确告诉GPT,如同下面的文本所示。
\n
You are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow.
\n\n常见的范式有:
\n回想一下🤔,当我们和GPT之类的产品进行交互时,我们的交互方式大致上有两类:\n举个例子,当我需要让GPT帮我写一个算法时,我可能会:
\n\n\n“我需要你写一段代码,这段代码第一行是
\ndef
,然后是函数名,然后是3个参数,然后是四行函数体。函数体中需要有return
。它第一行是……最后一行是……。”
这是一种典型的命令式交互,非常好使。
\n\n\n“直接说,我需要一个算法,这个算法需要满足以下要求:……”
\n
这是一种典型的声明式交互,主要关注结果的描述和需求,而不需要详细说明如何达到这个结果。
\n警告
\n声明式交互在代码实现上具有更大的风险,尤其是你缺乏对代码的深入理解时,比如李逵和李鬼:
\n\n重要
\n这里最核心的逻辑是,你和GPT之间的信息越一致,那么你得到的代码就越符合你的预期。
\n正是基于这个逻辑,我们才需要在第二步进行伪代码交互。
\n我提供一个比较极端的例子,假设你想要一个按照一定规则拆分矩阵的代码,并把结果存在你的类中,你和GPT的交互的伪代码如下:
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows
\n\n根据我的观察,如果你写了伪代码,在GPT的帮助下,它既可以是python也可以是C++,甚至可以是Java。它既可以是面向对象的,也可以是函数式的。你可以把更多的时间花在思考上,而不是写代码上。 算法上的革新带来的进步,远比你写代码tricks带来的进步要大。
\n再者,正如笑容不会消失,笑容只会从一个人的脸上转移到另一个人的脸上。复杂性也是一样的,复杂性不会消失,复杂性只会从这里转移到那里。在这里,我们可以尝试把复杂性转移到机器上。很多优秀的工程师都有这样的习惯,把代码写的像诗一样的优雅,充满了各种隐喻、抽象。也正是这个原因,维护自然语言的伪代码的复杂性,远比你维护代码的复杂性要低。
\n提示
\n诚然,大语言模型的技术一直在进步,但是,受限于其上下文能力,基于效率上的考虑,我们应该尝试把真实的工程进行模块化、结构化。
\n\n\nGPT先天的适合增量更新的模式,为了春分利用这一点,需要作为“架构师”的你首先对你的工程进行定义。
\n
提示
\n确保模块间的解耦,有些时候你会想用不同的大模型来完成不同的模块。
\n\n\n你可以参考下面的步骤来定义你的模块。
\n
提示
\n我利用刚刚例子中的伪代码和拆分模块的思想制作了promote,你可以在这里看到完整的上下文信息。
\n\n\n我创建了chatGPT(o1-mini模型)分享链接,点击链接,你可以在这里看到一个完整的例子。
\n
重要
\n1. 复制对GPT输入代码风格化的要求
\n--->>> 2. 编写包含你所有的要求和想法的伪代码
\n--------->>> 3. 拆分伪代码,分模块实现
\n\n\n具体的(注意代码块右侧的复制按钮):
\n
这里同上
\nYou are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow.
\n\n这里同上
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows”。 最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。
\n\n这里我们分块实现
\n我构思了一个矩阵拆分的算法,我定义我的模块有:0 验证用户的输入是否合适我们的拆分方法:如是否可以进行因式分解;1 生成矩阵;2 对矩阵进行拆分;3 把拆分后的矩阵和原有的矩阵在一张图片上叠加显示,着重显示拆分矩阵的边界。注意:技术选型为python3。我定义了第2部分的伪代码,代码如下“
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows
\n\n”。最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。
\n这里上面的提示词有些问题,我没有严格的定义可视化的方式,于是出现了问题。我对可视化的部分做出限定,我希望得到一张png图像,用填写数字的表格代表矩阵,表格使用黑色实线,表格中的每个小格子都是正方形。矩阵被切分的接缝处使用红色粗实线进行区分。
\n我在运行这段代码的时候遇到了问题,详细的上下文信息是“
\n% python test.py
\n\nMatrix Splitting Algorithm with Enhanced Visualization\n------------------------------------------------------\nEnter the number of rows and columns (e.g., '8 12'): 80 12\nGenerated matrix of size 80x12.\nRow factor: 4, Column factor: 4\nMatrix split into 20 row-wise submatrices.\nTotal small matrices after horizontal split: 60\nGenerated seam matrices for columns: 20 sets.\nTraceback (most recent call last):\n File \"/Users/hughes/docs/test.py\", line 195, in <module>\n main()\n File \"/Users/hughes/docs/test.py\", line 191, in main\n splitter.split_matrix()\n File \"/Users/hughes/docs/test.py\", line 99, in split_matrix\n seam_matrix = np.vstack((top_matrix[-1, :].reshape(1, -1), bottom_matrix[0, :].reshape(1, -1)))\n ~~~~~~~~~~^^^^^^^\nIndexError: index -1 is out of bounds for axis 0 with size 0”
\n\n非常好👍,下面我们再对可视化的部分进行功能点的新增,刚刚我们的代码实现了对于按列拆分时的可视化,我们在最终的图像上增加按行拆分矩阵时的线,用绿色的粗实线来表示。在绘图的部分外部套一个tqdm的进度展示,便于在终端中查阅进度。
\n#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\n\"\"\"\nMatrix Splitting Algorithm with Enhanced Visualization\n\nThis script captures user input for matrix dimensions, validates the input,\ngenerates a matrix, splits it based on factorization, and visualizes the\noriginal and split matrices with clearly defined grid lines and highlighted\nsplit boundaries. The final visualization is saved as a PNG image.\n\nEnhancements:\n1. Added green thick lines to represent row splits.\n2. Incorporated tqdm progress bars to monitor plotting progress.\n\nAuthor: OpenAI ChatGPT\nDate: 2024-11-08\n\"\"\"\n\nimport sys\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.patches import Rectangle\nfrom tqdm import tqdm # Import tqdm for progress bars\n\nclass MatrixSplitter:\n def __init__(self, rows, cols):\n \"\"\"\n Initializes the MatrixSplitter with the specified number of rows and columns.\n\n Parameters:\n rows (int): Number of rows in the matrix.\n cols (int): Number of columns in the matrix.\n \"\"\"\n self.rows = rows\n self.cols = cols\n self.matrix = None\n self.small_matrices = [] # 2D list: small_matrices[i][j]\n self.seam_matrices_cols = []\n self.seam_matrices_rows = []\n\n def smallest_factor_greater_than_three(self, n):\n \"\"\"\n Finds the smallest factor of n that is greater than three.\n\n Parameters:\n n (int): The number to find a factor for.\n\n Returns:\n int: The smallest factor greater than three, or n if no such factor exists.\n \"\"\"\n for i in range(4, n + 1):\n if n % i == 0:\n return i\n return n\n\n def generate_matrix(self):\n \"\"\"\n Generates a matrix with random integers between 0 and 99.\n \"\"\"\n self.matrix = np.random.randint(0, 100, size=(self.rows, self.cols))\n print(f\"Generated matrix of size {self.rows}x{self.cols}.\")\n\n def split_matrix(self):\n \"\"\"\n Splits the matrix into smaller matrices based on factorization.\n \"\"\"\n # Find factors\n row_factor = self.smallest_factor_greater_than_three(self.rows)\n col_factor = self.smallest_factor_greater_than_three(self.cols)\n print(f\"Row factor: {row_factor}, Column factor: {col_factor}\")\n\n # Calculate number of splits\n num_row_splits = self.rows // row_factor\n num_col_splits = self.cols // col_factor\n\n # First split: Vertical (rows)\n row_split = np.array_split(self.matrix, num_row_splits, axis=0)\n print(f\"Matrix split into {len(row_split)} row-wise submatrices.\")\n\n # Further split: Horizontal (columns)\n # Convert small_matrices to a 2D list\n for sub_matrix in row_split:\n cols_split = np.array_split(sub_matrix, num_col_splits, axis=1)\n self.small_matrices.append(cols_split)\n total_small_matrices = len(self.small_matrices) * num_col_splits\n print(f\"Total small matrices after horizontal split: {total_small_matrices}\")\n\n # Second split: Seam matrices for columns\n for sub_matrix in row_split:\n row_seams = []\n for j in range(num_col_splits - 1):\n last_col = sub_matrix[:, (j + 1) * col_factor - 1].reshape(-1, 1)\n next_col = sub_matrix[:, (j + 1) * col_factor].reshape(-1, 1)\n seam_matrix = np.hstack((last_col, next_col))\n row_seams.append(seam_matrix)\n self.seam_matrices_cols.append(row_seams)\n print(f\"Generated seam matrices for columns: {len(self.seam_matrices_cols)} sets.\")\n\n # Third split: Seam matrices for rows\n for i in range(num_row_splits - 1):\n row_seams = []\n for j in range(num_col_splits):\n # Access small_matrices as a 2D list\n top_matrix = self.small_matrices[i][j]\n bottom_matrix = self.small_matrices[i + 1][j]\n # Get the last row of top_matrix and first row of bottom_matrix\n top_last_row = top_matrix[-1, :].reshape(1, -1)\n bottom_first_row = bottom_matrix[0, :].reshape(1, -1)\n seam_matrix = np.vstack((top_last_row, bottom_first_row))\n row_seams.append(seam_matrix)\n self.seam_matrices_rows.append(row_seams)\n print(f\"Generated seam matrices for rows: {len(self.seam_matrices_rows)} sets.\")\n\n def visualize_splits(self, output_filename=\"matrix_split.png\"):\n \"\"\"\n Visualizes the original and split matrices as a numbered grid with black grid lines,\n red thick lines for column splits, and green thick lines for row splits.\n The visualization is saved as a PNG image.\n\n Parameters:\n output_filename (str): The filename for the saved PNG image.\n \"\"\"\n fig, ax = plt.subplots(figsize=(self.cols, self.rows))\n ax.set_xlim(0, self.cols)\n ax.set_ylim(0, self.rows)\n ax.set_xticks(np.arange(0, self.cols + 1, 1))\n ax.set_yticks(np.arange(0, self.rows + 1, 1))\n ax.set_xticklabels([])\n ax.set_yticklabels([])\n ax.grid(which='both', color='black', linewidth=1)\n\n # Invert y-axis to have the first row at the top\n ax.invert_yaxis()\n\n # Add numbers to each cell with a progress bar\n total_cells = self.rows * self.cols\n with tqdm(total=total_cells, desc=\"Plotting cells\", unit=\"cell\") as pbar:\n for i in range(self.rows):\n for j in range(self.cols):\n cell_value = self.matrix[i, j]\n ax.text(j + 0.5, i + 0.5, str(cell_value),\n va='center', ha='center', fontsize=8)\n pbar.update(1)\n\n # Highlight split boundaries with red thick lines (columns) and green thick lines (rows)\n row_factor = self.smallest_factor_greater_than_three(self.rows)\n col_factor = self.smallest_factor_greater_than_three(self.cols)\n\n # Horizontal split lines (rows) - Green\n with tqdm(total=self.rows // row_factor - 1, desc=\"Drawing row splits\", unit=\"split\") as pbar:\n for i in range(1, self.rows // row_factor):\n ax.axhline(i * row_factor, color='green', linewidth=2)\n pbar.update(1)\n\n # Vertical split lines (columns) - Red\n with tqdm(total=self.cols // col_factor - 1, desc=\"Drawing column splits\", unit=\"split\") as pbar:\n for j in range(1, self.cols // col_factor):\n ax.axvline(j * col_factor, color='red', linewidth=2)\n pbar.update(1)\n\n # Remove whitespace and axes\n plt.axis('off')\n plt.tight_layout()\n\n # Save the figure\n plt.savefig(output_filename, dpi=300, bbox_inches='tight')\n plt.close()\n print(f\"Visualization saved as '{output_filename}'.\")\n\ndef validate_input(input_str):\n \"\"\"\n Validates that the input string contains two integers greater than or equal to 4.\n\n Parameters:\n input_str (str): The input string containing two numbers.\n\n Returns:\n tuple: A tuple containing two integers (rows, cols).\n\n Raises:\n ValueError: If input is invalid.\n \"\"\"\n try:\n parts = input_str.strip().split()\n if len(parts) != 2:\n raise ValueError(\"Please enter exactly two numbers separated by space.\")\n rows, cols = map(int, parts)\n if rows < 4 or cols < 4:\n raise ValueError(\"Both dimensions must be at least 4.\")\n return rows, cols\n except Exception as e:\n raise ValueError(f\"Invalid input: {e}\")\n\ndef main():\n \"\"\"\n Main function to execute the matrix splitting algorithm.\n \"\"\"\n print(\"Matrix Splitting Algorithm with Enhanced Visualization\")\n print(\"------------------------------------------------------\")\n try:\n user_input = input(\"Enter the number of rows and columns (e.g., '8 12'): \")\n rows, cols = validate_input(user_input)\n except ValueError as ve:\n print(ve)\n sys.exit(1)\n\n splitter = MatrixSplitter(rows, cols)\n splitter.generate_matrix()\n splitter.split_matrix()\n splitter.visualize_splits()\n\nif __name__ == \"__main__\":\n main()
\n\n\n\n我必须在这里重申 “AI放大了人类的能力边界”,代码的最终结果极大的取决于 “人的思考” 的质量。
\n
在这里,我推荐书籍《人月神话》wiki,虽然此书是写于1975年,但数十年来多次重印。书中对软件工程的思考,对软件开发中人的因素的思考,非常值得阅读。
\nover
\n","env":{"base":"/WDL_Tools_docs/","filePath":"/Users/hughes/docs/WDL_Tools_docs/docs/notes/04_codeStyle/meandAI.md","filePathRelative":"notes/04_codeStyle/meandAI.md","frontmatter":{"title":"人工智能协助代码开发","createTime":"2024/11/07 14:45:46","permalink":"/04_codeStyle/meandAI/"},"sfcBlocks":{"template":{"type":"template","content":"1. 复制对GPT输入代码风格化的要求
\n--->>> 2. 编写包含你所有的要求和想法的伪代码
\n--------->>> 3. 拆分伪代码,分模块实现
\n\n\n本文通过几个例子展示了用GPT敲代码的几个模式,您需要确保您的键盘具有Ctrl键、C键、V键。
\n
\n\n受文本长度限制,本文尽量不对任何内容的驱动原理做出解释。
\n
注
\n重要
\nAI放大了人类的能力边界,但社会生活的主体依然是自然人。
\n\n\n跟我复制
\n
\n\n如果你有一些类似于“整洁代码”的偏好,或者你有明确的编程习惯,请在进行代码产出时,明确告诉GPT,如同下面的文本所示。
\n
You are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow.
\n\n常见的范式有:
\n回想一下🤔,当我们和GPT之类的产品进行交互时,我们的交互方式大致上有两类:\n举个例子,当我需要让GPT帮我写一个算法时,我可能会:
\n\n\n“我需要你写一段代码,这段代码第一行是
\ndef
,然后是函数名,然后是3个参数,然后是四行函数体。函数体中需要有return
。它第一行是……最后一行是……。”
这是一种典型的命令式交互,非常好使。
\n\n\n“直接说,我需要一个算法,这个算法需要满足以下要求:……”
\n
这是一种典型的声明式交互,主要关注结果的描述和需求,而不需要详细说明如何达到这个结果。
\n警告
\n声明式交互在代码实现上具有更大的风险,尤其是你缺乏对代码的深入理解时,比如李逵和李鬼:
\n\n重要
\n这里最核心的逻辑是,你和GPT之间的信息越一致,那么你得到的代码就越符合你的预期。
\n正是基于这个逻辑,我们才需要在第二步进行伪代码交互。
\n我提供一个比较极端的例子,假设你想要一个按照一定规则拆分矩阵的代码,并把结果存在你的类中,你和GPT的交互的伪代码如下:
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows
\n\n根据我的观察,如果你写了伪代码,在GPT的帮助下,它既可以是python也可以是C++,甚至可以是Java。它既可以是面向对象的,也可以是函数式的。你可以把更多的时间花在思考上,而不是写代码上。 算法上的革新带来的进步,远比你写代码tricks带来的进步要大。
\n再者,正如笑容不会消失,笑容只会从一个人的脸上转移到另一个人的脸上。复杂性也是一样的,复杂性不会消失,复杂性只会从这里转移到那里。在这里,我们可以尝试把复杂性转移到机器上。很多优秀的工程师都有这样的习惯,把代码写的像诗一样的优雅,充满了各种隐喻、抽象。也正是这个原因,维护自然语言的伪代码的复杂性,远比你维护代码的复杂性要低。
\n提示
\n诚然,大语言模型的技术一直在进步,但是,受限于其上下文能力,基于效率上的考虑,我们应该尝试把真实的工程进行模块化、结构化。
\n\n\nGPT先天的适合增量更新的模式,为了春分利用这一点,需要作为“架构师”的你首先对你的工程进行定义。
\n
提示
\n确保模块间的解耦,有些时候你会想用不同的大模型来完成不同的模块。
\n\n\n你可以参考下面的步骤来定义你的模块。
\n
提示
\n我利用刚刚例子中的伪代码和拆分模块的思想制作了promote,你可以在这里看到完整的上下文信息。
\n\n\n我创建了chatGPT(o1-mini模型)分享链接,点击链接,你可以在这里看到一个完整的例子。
\n
重要
\n1. 复制对GPT输入代码风格化的要求
\n--->>> 2. 编写包含你所有的要求和想法的伪代码
\n--------->>> 3. 拆分伪代码,分模块实现
\n\n\n具体的(注意代码块右侧的复制按钮):
\n
这里同上
\nYou are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow.
\n\n这里同上
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows”。 最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。
\n\n这里我们分块实现
\n我构思了一个矩阵拆分的算法,我定义我的模块有:0 验证用户的输入是否合适我们的拆分方法:如是否可以进行因式分解;1 生成矩阵;2 对矩阵进行拆分;3 把拆分后的矩阵和原有的矩阵在一张图片上叠加显示,着重显示拆分矩阵的边界。注意:技术选型为python3。我定义了第2部分的伪代码,代码如下“
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows
\n\n”。最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。
\n这里上面的提示词有些问题,我没有严格的定义可视化的方式,于是出现了问题。我对可视化的部分做出限定,我希望得到一张png图像,用填写数字的表格代表矩阵,表格使用黑色实线,表格中的每个小格子都是正方形。矩阵被切分的接缝处使用红色粗实线进行区分。
\n我在运行这段代码的时候遇到了问题,详细的上下文信息是“
\n% python test.py
\n\nMatrix Splitting Algorithm with Enhanced Visualization\n------------------------------------------------------\nEnter the number of rows and columns (e.g., '8 12'): 80 12\nGenerated matrix of size 80x12.\nRow factor: 4, Column factor: 4\nMatrix split into 20 row-wise submatrices.\nTotal small matrices after horizontal split: 60\nGenerated seam matrices for columns: 20 sets.\nTraceback (most recent call last):\n File \"/Users/hughes/docs/test.py\", line 195, in <module>\n main()\n File \"/Users/hughes/docs/test.py\", line 191, in main\n splitter.split_matrix()\n File \"/Users/hughes/docs/test.py\", line 99, in split_matrix\n seam_matrix = np.vstack((top_matrix[-1, :].reshape(1, -1), bottom_matrix[0, :].reshape(1, -1)))\n ~~~~~~~~~~^^^^^^^\nIndexError: index -1 is out of bounds for axis 0 with size 0”
\n\n非常好👍,下面我们再对可视化的部分进行功能点的新增,刚刚我们的代码实现了对于按列拆分时的可视化,我们在最终的图像上增加按行拆分矩阵时的线,用绿色的粗实线来表示。在绘图的部分外部套一个tqdm的进度展示,便于在终端中查阅进度。
\n#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\n\"\"\"\nMatrix Splitting Algorithm with Enhanced Visualization\n\nThis script captures user input for matrix dimensions, validates the input,\ngenerates a matrix, splits it based on factorization, and visualizes the\noriginal and split matrices with clearly defined grid lines and highlighted\nsplit boundaries. The final visualization is saved as a PNG image.\n\nEnhancements:\n1. Added green thick lines to represent row splits.\n2. Incorporated tqdm progress bars to monitor plotting progress.\n\nAuthor: OpenAI ChatGPT\nDate: 2024-11-08\n\"\"\"\n\nimport sys\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.patches import Rectangle\nfrom tqdm import tqdm # Import tqdm for progress bars\n\nclass MatrixSplitter:\n def __init__(self, rows, cols):\n \"\"\"\n Initializes the MatrixSplitter with the specified number of rows and columns.\n\n Parameters:\n rows (int): Number of rows in the matrix.\n cols (int): Number of columns in the matrix.\n \"\"\"\n self.rows = rows\n self.cols = cols\n self.matrix = None\n self.small_matrices = [] # 2D list: small_matrices[i][j]\n self.seam_matrices_cols = []\n self.seam_matrices_rows = []\n\n def smallest_factor_greater_than_three(self, n):\n \"\"\"\n Finds the smallest factor of n that is greater than three.\n\n Parameters:\n n (int): The number to find a factor for.\n\n Returns:\n int: The smallest factor greater than three, or n if no such factor exists.\n \"\"\"\n for i in range(4, n + 1):\n if n % i == 0:\n return i\n return n\n\n def generate_matrix(self):\n \"\"\"\n Generates a matrix with random integers between 0 and 99.\n \"\"\"\n self.matrix = np.random.randint(0, 100, size=(self.rows, self.cols))\n print(f\"Generated matrix of size {self.rows}x{self.cols}.\")\n\n def split_matrix(self):\n \"\"\"\n Splits the matrix into smaller matrices based on factorization.\n \"\"\"\n # Find factors\n row_factor = self.smallest_factor_greater_than_three(self.rows)\n col_factor = self.smallest_factor_greater_than_three(self.cols)\n print(f\"Row factor: {row_factor}, Column factor: {col_factor}\")\n\n # Calculate number of splits\n num_row_splits = self.rows // row_factor\n num_col_splits = self.cols // col_factor\n\n # First split: Vertical (rows)\n row_split = np.array_split(self.matrix, num_row_splits, axis=0)\n print(f\"Matrix split into {len(row_split)} row-wise submatrices.\")\n\n # Further split: Horizontal (columns)\n # Convert small_matrices to a 2D list\n for sub_matrix in row_split:\n cols_split = np.array_split(sub_matrix, num_col_splits, axis=1)\n self.small_matrices.append(cols_split)\n total_small_matrices = len(self.small_matrices) * num_col_splits\n print(f\"Total small matrices after horizontal split: {total_small_matrices}\")\n\n # Second split: Seam matrices for columns\n for sub_matrix in row_split:\n row_seams = []\n for j in range(num_col_splits - 1):\n last_col = sub_matrix[:, (j + 1) * col_factor - 1].reshape(-1, 1)\n next_col = sub_matrix[:, (j + 1) * col_factor].reshape(-1, 1)\n seam_matrix = np.hstack((last_col, next_col))\n row_seams.append(seam_matrix)\n self.seam_matrices_cols.append(row_seams)\n print(f\"Generated seam matrices for columns: {len(self.seam_matrices_cols)} sets.\")\n\n # Third split: Seam matrices for rows\n for i in range(num_row_splits - 1):\n row_seams = []\n for j in range(num_col_splits):\n # Access small_matrices as a 2D list\n top_matrix = self.small_matrices[i][j]\n bottom_matrix = self.small_matrices[i + 1][j]\n # Get the last row of top_matrix and first row of bottom_matrix\n top_last_row = top_matrix[-1, :].reshape(1, -1)\n bottom_first_row = bottom_matrix[0, :].reshape(1, -1)\n seam_matrix = np.vstack((top_last_row, bottom_first_row))\n row_seams.append(seam_matrix)\n self.seam_matrices_rows.append(row_seams)\n print(f\"Generated seam matrices for rows: {len(self.seam_matrices_rows)} sets.\")\n\n def visualize_splits(self, output_filename=\"matrix_split.png\"):\n \"\"\"\n Visualizes the original and split matrices as a numbered grid with black grid lines,\n red thick lines for column splits, and green thick lines for row splits.\n The visualization is saved as a PNG image.\n\n Parameters:\n output_filename (str): The filename for the saved PNG image.\n \"\"\"\n fig, ax = plt.subplots(figsize=(self.cols, self.rows))\n ax.set_xlim(0, self.cols)\n ax.set_ylim(0, self.rows)\n ax.set_xticks(np.arange(0, self.cols + 1, 1))\n ax.set_yticks(np.arange(0, self.rows + 1, 1))\n ax.set_xticklabels([])\n ax.set_yticklabels([])\n ax.grid(which='both', color='black', linewidth=1)\n\n # Invert y-axis to have the first row at the top\n ax.invert_yaxis()\n\n # Add numbers to each cell with a progress bar\n total_cells = self.rows * self.cols\n with tqdm(total=total_cells, desc=\"Plotting cells\", unit=\"cell\") as pbar:\n for i in range(self.rows):\n for j in range(self.cols):\n cell_value = self.matrix[i, j]\n ax.text(j + 0.5, i + 0.5, str(cell_value),\n va='center', ha='center', fontsize=8)\n pbar.update(1)\n\n # Highlight split boundaries with red thick lines (columns) and green thick lines (rows)\n row_factor = self.smallest_factor_greater_than_three(self.rows)\n col_factor = self.smallest_factor_greater_than_three(self.cols)\n\n # Horizontal split lines (rows) - Green\n with tqdm(total=self.rows // row_factor - 1, desc=\"Drawing row splits\", unit=\"split\") as pbar:\n for i in range(1, self.rows // row_factor):\n ax.axhline(i * row_factor, color='green', linewidth=2)\n pbar.update(1)\n\n # Vertical split lines (columns) - Red\n with tqdm(total=self.cols // col_factor - 1, desc=\"Drawing column splits\", unit=\"split\") as pbar:\n for j in range(1, self.cols // col_factor):\n ax.axvline(j * col_factor, color='red', linewidth=2)\n pbar.update(1)\n\n # Remove whitespace and axes\n plt.axis('off')\n plt.tight_layout()\n\n # Save the figure\n plt.savefig(output_filename, dpi=300, bbox_inches='tight')\n plt.close()\n print(f\"Visualization saved as '{output_filename}'.\")\n\ndef validate_input(input_str):\n \"\"\"\n Validates that the input string contains two integers greater than or equal to 4.\n\n Parameters:\n input_str (str): The input string containing two numbers.\n\n Returns:\n tuple: A tuple containing two integers (rows, cols).\n\n Raises:\n ValueError: If input is invalid.\n \"\"\"\n try:\n parts = input_str.strip().split()\n if len(parts) != 2:\n raise ValueError(\"Please enter exactly two numbers separated by space.\")\n rows, cols = map(int, parts)\n if rows < 4 or cols < 4:\n raise ValueError(\"Both dimensions must be at least 4.\")\n return rows, cols\n except Exception as e:\n raise ValueError(f\"Invalid input: {e}\")\n\ndef main():\n \"\"\"\n Main function to execute the matrix splitting algorithm.\n \"\"\"\n print(\"Matrix Splitting Algorithm with Enhanced Visualization\")\n print(\"------------------------------------------------------\")\n try:\n user_input = input(\"Enter the number of rows and columns (e.g., '8 12'): \")\n rows, cols = validate_input(user_input)\n except ValueError as ve:\n print(ve)\n sys.exit(1)\n\n splitter = MatrixSplitter(rows, cols)\n splitter.generate_matrix()\n splitter.split_matrix()\n splitter.visualize_splits()\n\nif __name__ == \"__main__\":\n main()
\n\n\n\n我必须在这里重申 “AI放大了人类的能力边界”,代码的最终结果极大的取决于 “人的思考” 的质量。
\n
在这里,我推荐书籍《人月神话》wiki,虽然此书是写于1975年,但数十年来多次重印。书中对软件工程的思考,对软件开发中人的因素的思考,非常值得阅读。
\nover
\n","contentStripped":"1. 复制对GPT输入代码风格化的要求
\n--->>> 2. 编写包含你所有的要求和想法的伪代码
\n--------->>> 3. 拆分伪代码,分模块实现
\n\n\n本文通过几个例子展示了用GPT敲代码的几个模式,您需要确保您的键盘具有Ctrl键、C键、V键。
\n
\n\n受文本长度限制,本文尽量不对任何内容的驱动原理做出解释。
\n
注
\n重要
\nAI放大了人类的能力边界,但社会生活的主体依然是自然人。
\n\n\n跟我复制
\n
\n\n如果你有一些类似于“整洁代码”的偏好,或者你有明确的编程习惯,请在进行代码产出时,明确告诉GPT,如同下面的文本所示。
\n
You are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow.
\n\n常见的范式有:
\n回想一下🤔,当我们和GPT之类的产品进行交互时,我们的交互方式大致上有两类:\n举个例子,当我需要让GPT帮我写一个算法时,我可能会:
\n\n\n“我需要你写一段代码,这段代码第一行是
\ndef
,然后是函数名,然后是3个参数,然后是四行函数体。函数体中需要有return
。它第一行是……最后一行是……。”
这是一种典型的命令式交互,非常好使。
\n\n\n“直接说,我需要一个算法,这个算法需要满足以下要求:……”
\n
这是一种典型的声明式交互,主要关注结果的描述和需求,而不需要详细说明如何达到这个结果。
\n警告
\n声明式交互在代码实现上具有更大的风险,尤其是你缺乏对代码的深入理解时,比如李逵和李鬼:
\n\n重要
\n这里最核心的逻辑是,你和GPT之间的信息越一致,那么你得到的代码就越符合你的预期。
\n正是基于这个逻辑,我们才需要在第二步进行伪代码交互。
\n我提供一个比较极端的例子,假设你想要一个按照一定规则拆分矩阵的代码,并把结果存在你的类中,你和GPT的交互的伪代码如下:
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows
\n\n根据我的观察,如果你写了伪代码,在GPT的帮助下,它既可以是python也可以是C++,甚至可以是Java。它既可以是面向对象的,也可以是函数式的。你可以把更多的时间花在思考上,而不是写代码上。 算法上的革新带来的进步,远比你写代码tricks带来的进步要大。
\n再者,正如笑容不会消失,笑容只会从一个人的脸上转移到另一个人的脸上。复杂性也是一样的,复杂性不会消失,复杂性只会从这里转移到那里。在这里,我们可以尝试把复杂性转移到机器上。很多优秀的工程师都有这样的习惯,把代码写的像诗一样的优雅,充满了各种隐喻、抽象。也正是这个原因,维护自然语言的伪代码的复杂性,远比你维护代码的复杂性要低。
\n提示
\n诚然,大语言模型的技术一直在进步,但是,受限于其上下文能力,基于效率上的考虑,我们应该尝试把真实的工程进行模块化、结构化。
\n\n\nGPT先天的适合增量更新的模式,为了春分利用这一点,需要作为“架构师”的你首先对你的工程进行定义。
\n
提示
\n确保模块间的解耦,有些时候你会想用不同的大模型来完成不同的模块。
\n\n\n你可以参考下面的步骤来定义你的模块。
\n
提示
\n我利用刚刚例子中的伪代码和拆分模块的思想制作了promote,你可以在这里看到完整的上下文信息。
\n\n\n我创建了chatGPT(o1-mini模型)分享链接,点击链接,你可以在这里看到一个完整的例子。
\n
重要
\n1. 复制对GPT输入代码风格化的要求
\n--->>> 2. 编写包含你所有的要求和想法的伪代码
\n--------->>> 3. 拆分伪代码,分模块实现
\n\n\n具体的(注意代码块右侧的复制按钮):
\n
这里同上
\nYou are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow.
\n\n这里同上
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows”。 最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。
\n\n这里我们分块实现
\n我构思了一个矩阵拆分的算法,我定义我的模块有:0 验证用户的输入是否合适我们的拆分方法:如是否可以进行因式分解;1 生成矩阵;2 对矩阵进行拆分;3 把拆分后的矩阵和原有的矩阵在一张图片上叠加显示,着重显示拆分矩阵的边界。注意:技术选型为python3。我定义了第2部分的伪代码,代码如下“
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows
\n\n”。最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。
\n这里上面的提示词有些问题,我没有严格的定义可视化的方式,于是出现了问题。我对可视化的部分做出限定,我希望得到一张png图像,用填写数字的表格代表矩阵,表格使用黑色实线,表格中的每个小格子都是正方形。矩阵被切分的接缝处使用红色粗实线进行区分。
\n我在运行这段代码的时候遇到了问题,详细的上下文信息是“
\n% python test.py
\n\nMatrix Splitting Algorithm with Enhanced Visualization\n------------------------------------------------------\nEnter the number of rows and columns (e.g., '8 12'): 80 12\nGenerated matrix of size 80x12.\nRow factor: 4, Column factor: 4\nMatrix split into 20 row-wise submatrices.\nTotal small matrices after horizontal split: 60\nGenerated seam matrices for columns: 20 sets.\nTraceback (most recent call last):\n File \"/Users/hughes/docs/test.py\", line 195, in <module>\n main()\n File \"/Users/hughes/docs/test.py\", line 191, in main\n splitter.split_matrix()\n File \"/Users/hughes/docs/test.py\", line 99, in split_matrix\n seam_matrix = np.vstack((top_matrix[-1, :].reshape(1, -1), bottom_matrix[0, :].reshape(1, -1)))\n ~~~~~~~~~~^^^^^^^\nIndexError: index -1 is out of bounds for axis 0 with size 0”
\n\n非常好👍,下面我们再对可视化的部分进行功能点的新增,刚刚我们的代码实现了对于按列拆分时的可视化,我们在最终的图像上增加按行拆分矩阵时的线,用绿色的粗实线来表示。在绘图的部分外部套一个tqdm的进度展示,便于在终端中查阅进度。
\n#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\n\"\"\"\nMatrix Splitting Algorithm with Enhanced Visualization\n\nThis script captures user input for matrix dimensions, validates the input,\ngenerates a matrix, splits it based on factorization, and visualizes the\noriginal and split matrices with clearly defined grid lines and highlighted\nsplit boundaries. The final visualization is saved as a PNG image.\n\nEnhancements:\n1. Added green thick lines to represent row splits.\n2. Incorporated tqdm progress bars to monitor plotting progress.\n\nAuthor: OpenAI ChatGPT\nDate: 2024-11-08\n\"\"\"\n\nimport sys\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.patches import Rectangle\nfrom tqdm import tqdm # Import tqdm for progress bars\n\nclass MatrixSplitter:\n def __init__(self, rows, cols):\n \"\"\"\n Initializes the MatrixSplitter with the specified number of rows and columns.\n\n Parameters:\n rows (int): Number of rows in the matrix.\n cols (int): Number of columns in the matrix.\n \"\"\"\n self.rows = rows\n self.cols = cols\n self.matrix = None\n self.small_matrices = [] # 2D list: small_matrices[i][j]\n self.seam_matrices_cols = []\n self.seam_matrices_rows = []\n\n def smallest_factor_greater_than_three(self, n):\n \"\"\"\n Finds the smallest factor of n that is greater than three.\n\n Parameters:\n n (int): The number to find a factor for.\n\n Returns:\n int: The smallest factor greater than three, or n if no such factor exists.\n \"\"\"\n for i in range(4, n + 1):\n if n % i == 0:\n return i\n return n\n\n def generate_matrix(self):\n \"\"\"\n Generates a matrix with random integers between 0 and 99.\n \"\"\"\n self.matrix = np.random.randint(0, 100, size=(self.rows, self.cols))\n print(f\"Generated matrix of size {self.rows}x{self.cols}.\")\n\n def split_matrix(self):\n \"\"\"\n Splits the matrix into smaller matrices based on factorization.\n \"\"\"\n # Find factors\n row_factor = self.smallest_factor_greater_than_three(self.rows)\n col_factor = self.smallest_factor_greater_than_three(self.cols)\n print(f\"Row factor: {row_factor}, Column factor: {col_factor}\")\n\n # Calculate number of splits\n num_row_splits = self.rows // row_factor\n num_col_splits = self.cols // col_factor\n\n # First split: Vertical (rows)\n row_split = np.array_split(self.matrix, num_row_splits, axis=0)\n print(f\"Matrix split into {len(row_split)} row-wise submatrices.\")\n\n # Further split: Horizontal (columns)\n # Convert small_matrices to a 2D list\n for sub_matrix in row_split:\n cols_split = np.array_split(sub_matrix, num_col_splits, axis=1)\n self.small_matrices.append(cols_split)\n total_small_matrices = len(self.small_matrices) * num_col_splits\n print(f\"Total small matrices after horizontal split: {total_small_matrices}\")\n\n # Second split: Seam matrices for columns\n for sub_matrix in row_split:\n row_seams = []\n for j in range(num_col_splits - 1):\n last_col = sub_matrix[:, (j + 1) * col_factor - 1].reshape(-1, 1)\n next_col = sub_matrix[:, (j + 1) * col_factor].reshape(-1, 1)\n seam_matrix = np.hstack((last_col, next_col))\n row_seams.append(seam_matrix)\n self.seam_matrices_cols.append(row_seams)\n print(f\"Generated seam matrices for columns: {len(self.seam_matrices_cols)} sets.\")\n\n # Third split: Seam matrices for rows\n for i in range(num_row_splits - 1):\n row_seams = []\n for j in range(num_col_splits):\n # Access small_matrices as a 2D list\n top_matrix = self.small_matrices[i][j]\n bottom_matrix = self.small_matrices[i + 1][j]\n # Get the last row of top_matrix and first row of bottom_matrix\n top_last_row = top_matrix[-1, :].reshape(1, -1)\n bottom_first_row = bottom_matrix[0, :].reshape(1, -1)\n seam_matrix = np.vstack((top_last_row, bottom_first_row))\n row_seams.append(seam_matrix)\n self.seam_matrices_rows.append(row_seams)\n print(f\"Generated seam matrices for rows: {len(self.seam_matrices_rows)} sets.\")\n\n def visualize_splits(self, output_filename=\"matrix_split.png\"):\n \"\"\"\n Visualizes the original and split matrices as a numbered grid with black grid lines,\n red thick lines for column splits, and green thick lines for row splits.\n The visualization is saved as a PNG image.\n\n Parameters:\n output_filename (str): The filename for the saved PNG image.\n \"\"\"\n fig, ax = plt.subplots(figsize=(self.cols, self.rows))\n ax.set_xlim(0, self.cols)\n ax.set_ylim(0, self.rows)\n ax.set_xticks(np.arange(0, self.cols + 1, 1))\n ax.set_yticks(np.arange(0, self.rows + 1, 1))\n ax.set_xticklabels([])\n ax.set_yticklabels([])\n ax.grid(which='both', color='black', linewidth=1)\n\n # Invert y-axis to have the first row at the top\n ax.invert_yaxis()\n\n # Add numbers to each cell with a progress bar\n total_cells = self.rows * self.cols\n with tqdm(total=total_cells, desc=\"Plotting cells\", unit=\"cell\") as pbar:\n for i in range(self.rows):\n for j in range(self.cols):\n cell_value = self.matrix[i, j]\n ax.text(j + 0.5, i + 0.5, str(cell_value),\n va='center', ha='center', fontsize=8)\n pbar.update(1)\n\n # Highlight split boundaries with red thick lines (columns) and green thick lines (rows)\n row_factor = self.smallest_factor_greater_than_three(self.rows)\n col_factor = self.smallest_factor_greater_than_three(self.cols)\n\n # Horizontal split lines (rows) - Green\n with tqdm(total=self.rows // row_factor - 1, desc=\"Drawing row splits\", unit=\"split\") as pbar:\n for i in range(1, self.rows // row_factor):\n ax.axhline(i * row_factor, color='green', linewidth=2)\n pbar.update(1)\n\n # Vertical split lines (columns) - Red\n with tqdm(total=self.cols // col_factor - 1, desc=\"Drawing column splits\", unit=\"split\") as pbar:\n for j in range(1, self.cols // col_factor):\n ax.axvline(j * col_factor, color='red', linewidth=2)\n pbar.update(1)\n\n # Remove whitespace and axes\n plt.axis('off')\n plt.tight_layout()\n\n # Save the figure\n plt.savefig(output_filename, dpi=300, bbox_inches='tight')\n plt.close()\n print(f\"Visualization saved as '{output_filename}'.\")\n\ndef validate_input(input_str):\n \"\"\"\n Validates that the input string contains two integers greater than or equal to 4.\n\n Parameters:\n input_str (str): The input string containing two numbers.\n\n Returns:\n tuple: A tuple containing two integers (rows, cols).\n\n Raises:\n ValueError: If input is invalid.\n \"\"\"\n try:\n parts = input_str.strip().split()\n if len(parts) != 2:\n raise ValueError(\"Please enter exactly two numbers separated by space.\")\n rows, cols = map(int, parts)\n if rows < 4 or cols < 4:\n raise ValueError(\"Both dimensions must be at least 4.\")\n return rows, cols\n except Exception as e:\n raise ValueError(f\"Invalid input: {e}\")\n\ndef main():\n \"\"\"\n Main function to execute the matrix splitting algorithm.\n \"\"\"\n print(\"Matrix Splitting Algorithm with Enhanced Visualization\")\n print(\"------------------------------------------------------\")\n try:\n user_input = input(\"Enter the number of rows and columns (e.g., '8 12'): \")\n rows, cols = validate_input(user_input)\n except ValueError as ve:\n print(ve)\n sys.exit(1)\n\n splitter = MatrixSplitter(rows, cols)\n splitter.generate_matrix()\n splitter.split_matrix()\n splitter.visualize_splits()\n\nif __name__ == \"__main__\":\n main()
\n\n\n\n我必须在这里重申 “AI放大了人类的能力边界”,代码的最终结果极大的取决于 “人的思考” 的质量。
\n
在这里,我推荐书籍《人月神话》wiki,虽然此书是写于1975年,但数十年来多次重印。书中对软件工程的思考,对软件开发中人的因素的思考,非常值得阅读。
\nover
\n","tagOpen":"","tagClose":""},"script":null,"scriptSetup":null,"scripts":[],"styles":[],"customBlocks":[]},"content":"## 快速实现公式\n\n- **1. 复制对GPT输入代码风格化的要求**\n\n- **--->>> 2. 编写包含你所有的要求和想法的伪代码**\n\n- **--------->>> 3. 拆分伪代码,分模块实现**\n\n## 引言\n\n> 本文通过几个例子展示了用GPT敲代码的几个模式,您需要确保您的键盘具有Ctrl键、C键、V键。\n\n> 受文本长度限制,本文尽量不对任何内容的驱动原理做出解释。\n\n#### 读者应该明确\n> [!note]\n> 1. **工程控制论正在推动电子计算机技术革命的深入。这样一个现实已经来到了人类面前: 由电子计算机和机器智能装备起来的人,已经成为更有作为、更高超的人! ———钱学森 《工程控制论·序言》**\n> 2. **君子不器。 ———孔子《论语·为政篇》**\n> 3. **[“值得怀疑的是,一切已有的机械发明,是否减轻了任何人每天的辛劳。”](https://www.marxists.org/chinese/marx-engels-2/44/019.htm) ———约翰·斯图亚特·穆勒《政治经济学原理》**\n\n::: important 重要\nAI放大了人类的能力边界,但社会生活的主体依然是自然人。\n:::\n\n## 第一部分:对GPT输入代码风格化的要求\n\n> 跟我复制\n\n> 如果你有一些类似于“整洁代码”的偏好,或者你有明确的编程习惯,请在进行代码产出时,明确告诉GPT,如同下面的文本所示。\n\n```txt :collapsed-lines=8\nYou are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow. \n```\n\n## 第二部分:把你的想法转换为伪代码或类似的逻辑描述\n\n### 📏范式\n\n常见的范式有:\n- ==命令式编程(Imperative Programming)==\n 程序由一系列的命令或语句组成,计算机按照这些命令执行操作。这是最早也是最基本的编程范式。典型代表:C 和 Java\n - ==声明式编程(Declarative Programming)==:程序员只需要描述他们想要的结果,而不需要详细说明如何达到这个结果。典型代表:SQL 和 HTML \n - ==面向对象编程(Object-Oriented Programming)==:程序被组织成对象,每个对象都包含数据和操作数据的方法。面向对象编程强调的是数据抽象和封装,以及对象之间的交互。典型代表:Java 和 Python\n\n### 为什么需要伪代码?\n\n回想一下🤔,当我们和GPT之类的产品进行交互时,我们的交互方式大致上有两类:\n举个例子,当我需要让GPT帮我写一个算法时,我可能会:\n#### 第一种交互方式\n> “我需要你写一段代码,这段代码第一行是`def`,然后是函数名,然后是3个参数,然后是四行函数体。函数体中需要有`return`。它第一行是……最后一行是……。”\n\n这是一种典型的命令式交互,非常好使。\n\n#### 第二种交互方式\n> “直接说,我需要一个算法,这个算法需要满足以下要求:……”\n\n这是一种典型的声明式交互,主要关注结果的描述和需求,而不需要详细说明如何达到这个结果。\n\n::: warning 警告\n\n声明式交互在代码实现上具有更大的风险,尤其是==你缺乏对代码的深入理解时==,比如李逵和李鬼:\n\n![Alt text](http://k.sinaimg.cn/n/sinacn/w500h229/20180102/7226-fyqefvx1303978.jpg/w700d1q75cms.jpg?by=cms_fixed_width)\n:::\n\n::: important 重要\n\n- 这里最**核心的逻辑**是,你和GPT之间的信息越一致,那么你得到的代码就越符合你的预期。\n\n- 正是基于这个逻辑,我们才需要在第二步进行==伪代码交互==。\n\n:::\n\n#### 伪代码的交互\n\n我提供一个比较极端的例子,假设你想要一个按照一定规则拆分矩阵的代码,并把结果存在你的类中,你和GPT的交互的伪代码如下:\n\n```python\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows\n```\n\n::: tip 提示\n### 🙋好,那么好,这时候聪明的你就要问了:\n> # “我都写到这种程度了,为什么我不亲自写一遍?好像工作量是差不多的。”\n\n:::\n\n根据我的观察,如果你写了伪代码,在GPT的帮助下,它既可以是python也可以是C++,甚至可以是Java。它既可以是面向对象的,也可以是函数式的。==你可以把更多的时间花在思考上,而不是写代码上。== 算法上的革新带来的进步,远比你写代码tricks带来的进步要大。\n\n再者,正如笑容不会消失,笑容只会从一个人的脸上转移到另一个人的脸上。复杂性也是一样的,复杂性不会消失,复杂性只会从这里转移到那里。在这里,我们可以尝试把复杂性转移到机器上。很多优秀的工程师都有这样的习惯,把代码写的像诗一样的优雅,充满了各种隐喻、抽象。也正是这个原因,维护自然语言的伪代码的复杂性,远比你维护代码的复杂性要低。\n\n## 第三部分:怎么让GPT整点复杂的东西?\n\n::: tip 提示\n诚然,大语言模型的技术一直在进步,但是,受限于其上下文能力,基于效率上的考虑,我们应该尝试把真实的工程进行模块化、结构化。\n:::\n\n### 这一点和完成一个大型工程一摸一样\n\n> GPT先天的适合增量更新的模式,为了春分利用这一点,需要作为“架构师”的你首先对你的工程进行定义。\n\n::: tip 提示\n确保模块间的解耦,有些时候你会想用不同的大模型来完成不同的模块。\n:::\n\n> 你可以参考下面的步骤来定义你的模块。\n\n### **3.1 定义互相解耦的模块**\n1. **模块划分原则**\n - 高内聚低耦合\n - 明确的接口和责任\n2. **识别关键功能模块**\n - 功能分解的方法\n - 示例:将一个Web应用划分为前端、后端、数据库等模块\n3. **接口设计**\n - 模块间通信的标准\n - 使用API和协议确保模块独立性\n\n### **3.2 模块化的实施步骤**\n1. **需求分析与功能分解**\n - 收集和分析项目需求\n - 将需求转化为功能模块\n2. **模块设计与规划**\n - 为每个模块制定详细设计\n - 确定模块之间的依赖关系\n3. **逐个模块的开发与测试**\n - 按照规划顺序开发模块\n - 独立测试每个模块的功能和性能\n4. **集成与系统测试**\n - 将各模块集成到整体系统中\n - 进行系统级别的测试和优化\n\n### **3.3 利用GPT进行模块化开发**\n\n#### 1. 分块粘贴伪代码\n\n## 作为结论\n\n### 实践:让我们在这里引入一个具体的例子\n\n::: tip 提示\n我利用刚刚例子中的伪代码和拆分模块的思想制作了promote,你可以在这里看到完整的上下文信息。\n> 我创建了chatGPT(o1-mini模型)[分享链接](https://chatgpt.com/share/66e56444-484d-484d-984d-484d484d484d),点击链接,你可以在这里看到一个完整的例子。\n:::\n\n::: important 重要\n\n### 我们实际上做了什么?\n\n- **1. 复制对GPT输入代码风格化的要求**\n\n- **--->>> 2. 编写包含你所有的要求和想法的伪代码**\n\n- **--------->>> 3. 拆分伪代码,分模块实现**\n\n:::\n\n> ==具体的==(注意代码块右侧的复制按钮):\n::: tabs\n\n@tab 1/5 复制\n\n==这里同上==\n```txt :collapsed-lines=8\nYou are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow. \n```\n\n@tab 2/5 编写伪代码\n\n==这里同上==\n\n```python :collapsed-lines=10\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows”。 最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。\n```\n\n@tab:active 3/5 先主体\n\n==这里我们分块实现==\n\n#### **主体部分**\n\n我构思了一个矩阵拆分的算法,我定义我的模块有:0 验证用户的输入是否合适我们的拆分方法:如是否可以进行因式分解;1 生成矩阵;2 对矩阵进行拆分;3 把拆分后的矩阵和原有的矩阵在一张图片上叠加显示,着重显示拆分矩阵的边界。注意:技术选型为python3。我定义了第2部分的伪代码,代码如下“\n\n```python :collapsed-lines=5\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows\n```\n”。最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。\n\n@tab:active 4/5 进一步进行限定\n#### **模块1**\n\n这里上面的提示词有些问题,我没有严格的定义可视化的方式,于是出现了问题。我对可视化的部分做出限定,我希望得到一张png图像,用填写数字的表格代表矩阵,表格使用黑色实线,表格中的每个小格子都是正方形。矩阵被切分的接缝处使用红色粗实线进行区分。\n\n#### **debug**\n\n我在运行这段代码的时候遇到了问题,详细的上下文信息是“ \n```shell\n% python test.py\n```\n\n```python :collapsed-lines=5\nMatrix Splitting Algorithm with Enhanced Visualization\n------------------------------------------------------\nEnter the number of rows and columns (e.g., '8 12'): 80 12\nGenerated matrix of size 80x12.\nRow factor: 4, Column factor: 4\nMatrix split into 20 row-wise submatrices.\nTotal small matrices after horizontal split: 60\nGenerated seam matrices for columns: 20 sets.\nTraceback (most recent call last):\n File \"/Users/hughes/docs/test.py\", line 195, in1. 复制对GPT输入代码风格化的要求
\n--->>> 2. 编写包含你所有的要求和想法的伪代码
\n--------->>> 3. 拆分伪代码,分模块实现
\n\n\n本文通过几个例子展示了用GPT敲代码的几个模式,您需要确保您的键盘具有Ctrl键、C键、V键。
\n
\n\n受文本长度限制,本文尽量不对任何内容的驱动原理做出解释。
\n
注
\n重要
\nAI放大了人类的能力边界,但社会生活的主体依然是自然人。
\n\n\n跟我复制
\n
\n\n如果你有一些类似于“整洁代码”的偏好,或者你有明确的编程习惯,请在进行代码产出时,明确告诉GPT,如同下面的文本所示。
\n
You are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow.
\n\n常见的范式有:
\n回想一下🤔,当我们和GPT之类的产品进行交互时,我们的交互方式大致上有两类:\n举个例子,当我需要让GPT帮我写一个算法时,我可能会:
\n\n\n“我需要你写一段代码,这段代码第一行是
\ndef
,然后是函数名,然后是3个参数,然后是四行函数体。函数体中需要有return
。它第一行是……最后一行是……。”
这是一种典型的命令式交互,非常好使。
\n\n\n“直接说,我需要一个算法,这个算法需要满足以下要求:……”
\n
这是一种典型的声明式交互,主要关注结果的描述和需求,而不需要详细说明如何达到这个结果。
\n警告
\n声明式交互在代码实现上具有更大的风险,尤其是你缺乏对代码的深入理解时,比如李逵和李鬼:
\n\n重要
\n这里最核心的逻辑是,你和GPT之间的信息越一致,那么你得到的代码就越符合你的预期。
\n正是基于这个逻辑,我们才需要在第二步进行伪代码交互。
\n我提供一个比较极端的例子,假设你想要一个按照一定规则拆分矩阵的代码,并把结果存在你的类中,你和GPT的交互的伪代码如下:
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows
\n\n根据我的观察,如果你写了伪代码,在GPT的帮助下,它既可以是python也可以是C++,甚至可以是Java。它既可以是面向对象的,也可以是函数式的。你可以把更多的时间花在思考上,而不是写代码上。 算法上的革新带来的进步,远比你写代码tricks带来的进步要大。
\n再者,正如笑容不会消失,笑容只会从一个人的脸上转移到另一个人的脸上。复杂性也是一样的,复杂性不会消失,复杂性只会从这里转移到那里。在这里,我们可以尝试把复杂性转移到机器上。很多优秀的工程师都有这样的习惯,把代码写的像诗一样的优雅,充满了各种隐喻、抽象。也正是这个原因,维护自然语言的伪代码的复杂性,远比你维护代码的复杂性要低。
\n提示
\n诚然,大语言模型的技术一直在进步,但是,受限于其上下文能力,基于效率上的考虑,我们应该尝试把真实的工程进行模块化、结构化。
\n\n\nGPT先天的适合增量更新的模式,为了春分利用这一点,需要作为“架构师”的你首先对你的工程进行定义。
\n
提示
\n确保模块间的解耦,有些时候你会想用不同的大模型来完成不同的模块。
\n\n\n你可以参考下面的步骤来定义你的模块。
\n
提示
\n我利用刚刚例子中的伪代码和拆分模块的思想制作了promote,你可以在这里看到完整的上下文信息。
\n\n\n我创建了chatGPT(o1-mini模型)分享链接,点击链接,你可以在这里看到一个完整的例子。
\n
重要
\n1. 复制对GPT输入代码风格化的要求
\n--->>> 2. 编写包含你所有的要求和想法的伪代码
\n--------->>> 3. 拆分伪代码,分模块实现
\n\n\n具体的(注意代码块右侧的复制按钮):
\n
这里同上
\nYou are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow.
\n\n这里同上
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows”。 最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。
\n\n这里我们分块实现
\n我构思了一个矩阵拆分的算法,我定义我的模块有:0 验证用户的输入是否合适我们的拆分方法:如是否可以进行因式分解;1 生成矩阵;2 对矩阵进行拆分;3 把拆分后的矩阵和原有的矩阵在一张图片上叠加显示,着重显示拆分矩阵的边界。注意:技术选型为python3。我定义了第2部分的伪代码,代码如下“
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows
\n\n”。最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。
\n这里上面的提示词有些问题,我没有严格的定义可视化的方式,于是出现了问题。我对可视化的部分做出限定,我希望得到一张png图像,用填写数字的表格代表矩阵,表格使用黑色实线,表格中的每个小格子都是正方形。矩阵被切分的接缝处使用红色粗实线进行区分。
\n我在运行这段代码的时候遇到了问题,详细的上下文信息是“
\n% python test.py
\n\nMatrix Splitting Algorithm with Enhanced Visualization\n------------------------------------------------------\nEnter the number of rows and columns (e.g., '8 12'): 80 12\nGenerated matrix of size 80x12.\nRow factor: 4, Column factor: 4\nMatrix split into 20 row-wise submatrices.\nTotal small matrices after horizontal split: 60\nGenerated seam matrices for columns: 20 sets.\nTraceback (most recent call last):\n File \"/Users/hughes/docs/test.py\", line 195, in <module>\n main()\n File \"/Users/hughes/docs/test.py\", line 191, in main\n splitter.split_matrix()\n File \"/Users/hughes/docs/test.py\", line 99, in split_matrix\n seam_matrix = np.vstack((top_matrix[-1, :].reshape(1, -1), bottom_matrix[0, :].reshape(1, -1)))\n ~~~~~~~~~~^^^^^^^\nIndexError: index -1 is out of bounds for axis 0 with size 0”
\n\n非常好👍,下面我们再对可视化的部分进行功能点的新增,刚刚我们的代码实现了对于按列拆分时的可视化,我们在最终的图像上增加按行拆分矩阵时的线,用绿色的粗实线来表示。在绘图的部分外部套一个tqdm的进度展示,便于在终端中查阅进度。
\n#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\n\"\"\"\nMatrix Splitting Algorithm with Enhanced Visualization\n\nThis script captures user input for matrix dimensions, validates the input,\ngenerates a matrix, splits it based on factorization, and visualizes the\noriginal and split matrices with clearly defined grid lines and highlighted\nsplit boundaries. The final visualization is saved as a PNG image.\n\nEnhancements:\n1. Added green thick lines to represent row splits.\n2. Incorporated tqdm progress bars to monitor plotting progress.\n\nAuthor: OpenAI ChatGPT\nDate: 2024-11-08\n\"\"\"\n\nimport sys\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.patches import Rectangle\nfrom tqdm import tqdm # Import tqdm for progress bars\n\nclass MatrixSplitter:\n def __init__(self, rows, cols):\n \"\"\"\n Initializes the MatrixSplitter with the specified number of rows and columns.\n\n Parameters:\n rows (int): Number of rows in the matrix.\n cols (int): Number of columns in the matrix.\n \"\"\"\n self.rows = rows\n self.cols = cols\n self.matrix = None\n self.small_matrices = [] # 2D list: small_matrices[i][j]\n self.seam_matrices_cols = []\n self.seam_matrices_rows = []\n\n def smallest_factor_greater_than_three(self, n):\n \"\"\"\n Finds the smallest factor of n that is greater than three.\n\n Parameters:\n n (int): The number to find a factor for.\n\n Returns:\n int: The smallest factor greater than three, or n if no such factor exists.\n \"\"\"\n for i in range(4, n + 1):\n if n % i == 0:\n return i\n return n\n\n def generate_matrix(self):\n \"\"\"\n Generates a matrix with random integers between 0 and 99.\n \"\"\"\n self.matrix = np.random.randint(0, 100, size=(self.rows, self.cols))\n print(f\"Generated matrix of size {self.rows}x{self.cols}.\")\n\n def split_matrix(self):\n \"\"\"\n Splits the matrix into smaller matrices based on factorization.\n \"\"\"\n # Find factors\n row_factor = self.smallest_factor_greater_than_three(self.rows)\n col_factor = self.smallest_factor_greater_than_three(self.cols)\n print(f\"Row factor: {row_factor}, Column factor: {col_factor}\")\n\n # Calculate number of splits\n num_row_splits = self.rows // row_factor\n num_col_splits = self.cols // col_factor\n\n # First split: Vertical (rows)\n row_split = np.array_split(self.matrix, num_row_splits, axis=0)\n print(f\"Matrix split into {len(row_split)} row-wise submatrices.\")\n\n # Further split: Horizontal (columns)\n # Convert small_matrices to a 2D list\n for sub_matrix in row_split:\n cols_split = np.array_split(sub_matrix, num_col_splits, axis=1)\n self.small_matrices.append(cols_split)\n total_small_matrices = len(self.small_matrices) * num_col_splits\n print(f\"Total small matrices after horizontal split: {total_small_matrices}\")\n\n # Second split: Seam matrices for columns\n for sub_matrix in row_split:\n row_seams = []\n for j in range(num_col_splits - 1):\n last_col = sub_matrix[:, (j + 1) * col_factor - 1].reshape(-1, 1)\n next_col = sub_matrix[:, (j + 1) * col_factor].reshape(-1, 1)\n seam_matrix = np.hstack((last_col, next_col))\n row_seams.append(seam_matrix)\n self.seam_matrices_cols.append(row_seams)\n print(f\"Generated seam matrices for columns: {len(self.seam_matrices_cols)} sets.\")\n\n # Third split: Seam matrices for rows\n for i in range(num_row_splits - 1):\n row_seams = []\n for j in range(num_col_splits):\n # Access small_matrices as a 2D list\n top_matrix = self.small_matrices[i][j]\n bottom_matrix = self.small_matrices[i + 1][j]\n # Get the last row of top_matrix and first row of bottom_matrix\n top_last_row = top_matrix[-1, :].reshape(1, -1)\n bottom_first_row = bottom_matrix[0, :].reshape(1, -1)\n seam_matrix = np.vstack((top_last_row, bottom_first_row))\n row_seams.append(seam_matrix)\n self.seam_matrices_rows.append(row_seams)\n print(f\"Generated seam matrices for rows: {len(self.seam_matrices_rows)} sets.\")\n\n def visualize_splits(self, output_filename=\"matrix_split.png\"):\n \"\"\"\n Visualizes the original and split matrices as a numbered grid with black grid lines,\n red thick lines for column splits, and green thick lines for row splits.\n The visualization is saved as a PNG image.\n\n Parameters:\n output_filename (str): The filename for the saved PNG image.\n \"\"\"\n fig, ax = plt.subplots(figsize=(self.cols, self.rows))\n ax.set_xlim(0, self.cols)\n ax.set_ylim(0, self.rows)\n ax.set_xticks(np.arange(0, self.cols + 1, 1))\n ax.set_yticks(np.arange(0, self.rows + 1, 1))\n ax.set_xticklabels([])\n ax.set_yticklabels([])\n ax.grid(which='both', color='black', linewidth=1)\n\n # Invert y-axis to have the first row at the top\n ax.invert_yaxis()\n\n # Add numbers to each cell with a progress bar\n total_cells = self.rows * self.cols\n with tqdm(total=total_cells, desc=\"Plotting cells\", unit=\"cell\") as pbar:\n for i in range(self.rows):\n for j in range(self.cols):\n cell_value = self.matrix[i, j]\n ax.text(j + 0.5, i + 0.5, str(cell_value),\n va='center', ha='center', fontsize=8)\n pbar.update(1)\n\n # Highlight split boundaries with red thick lines (columns) and green thick lines (rows)\n row_factor = self.smallest_factor_greater_than_three(self.rows)\n col_factor = self.smallest_factor_greater_than_three(self.cols)\n\n # Horizontal split lines (rows) - Green\n with tqdm(total=self.rows // row_factor - 1, desc=\"Drawing row splits\", unit=\"split\") as pbar:\n for i in range(1, self.rows // row_factor):\n ax.axhline(i * row_factor, color='green', linewidth=2)\n pbar.update(1)\n\n # Vertical split lines (columns) - Red\n with tqdm(total=self.cols // col_factor - 1, desc=\"Drawing column splits\", unit=\"split\") as pbar:\n for j in range(1, self.cols // col_factor):\n ax.axvline(j * col_factor, color='red', linewidth=2)\n pbar.update(1)\n\n # Remove whitespace and axes\n plt.axis('off')\n plt.tight_layout()\n\n # Save the figure\n plt.savefig(output_filename, dpi=300, bbox_inches='tight')\n plt.close()\n print(f\"Visualization saved as '{output_filename}'.\")\n\ndef validate_input(input_str):\n \"\"\"\n Validates that the input string contains two integers greater than or equal to 4.\n\n Parameters:\n input_str (str): The input string containing two numbers.\n\n Returns:\n tuple: A tuple containing two integers (rows, cols).\n\n Raises:\n ValueError: If input is invalid.\n \"\"\"\n try:\n parts = input_str.strip().split()\n if len(parts) != 2:\n raise ValueError(\"Please enter exactly two numbers separated by space.\")\n rows, cols = map(int, parts)\n if rows < 4 or cols < 4:\n raise ValueError(\"Both dimensions must be at least 4.\")\n return rows, cols\n except Exception as e:\n raise ValueError(f\"Invalid input: {e}\")\n\ndef main():\n \"\"\"\n Main function to execute the matrix splitting algorithm.\n \"\"\"\n print(\"Matrix Splitting Algorithm with Enhanced Visualization\")\n print(\"------------------------------------------------------\")\n try:\n user_input = input(\"Enter the number of rows and columns (e.g., '8 12'): \")\n rows, cols = validate_input(user_input)\n except ValueError as ve:\n print(ve)\n sys.exit(1)\n\n splitter = MatrixSplitter(rows, cols)\n splitter.generate_matrix()\n splitter.split_matrix()\n splitter.visualize_splits()\n\nif __name__ == \"__main__\":\n main()
\n\n\n\n\n仔细看看下面的代码,这就是你加上o1-mini的能力
\n
\n\n我必须在这里重申 “AI放大了人类的能力边界”,代码的最终结果极大的取决于 “人的思考” 的质量。
\n
在这里,我推荐书籍《人月神话》wiki,虽然此书是写于1975年,但数十年来多次重印。书中对软件工程的思考,对软件开发中人的因素的思考,非常值得阅读。
\nover
\n","env":{"base":"/WDL_Tools_docs/","filePath":"/Users/hughes/docs/WDL_Tools_docs/docs/notes/04_codeStyle/meandAI.md","filePathRelative":"notes/04_codeStyle/meandAI.md","frontmatter":{"title":"人工智能协助代码开发","createTime":"2024/11/07 14:45:46","permalink":"/04_codeStyle/meandAI/"},"sfcBlocks":{"template":{"type":"template","content":"1. 复制对GPT输入代码风格化的要求
\n--->>> 2. 编写包含你所有的要求和想法的伪代码
\n--------->>> 3. 拆分伪代码,分模块实现
\n\n\n本文通过几个例子展示了用GPT敲代码的几个模式,您需要确保您的键盘具有Ctrl键、C键、V键。
\n
\n\n受文本长度限制,本文尽量不对任何内容的驱动原理做出解释。
\n
注
\n重要
\nAI放大了人类的能力边界,但社会生活的主体依然是自然人。
\n\n\n跟我复制
\n
\n\n如果你有一些类似于“整洁代码”的偏好,或者你有明确的编程习惯,请在进行代码产出时,明确告诉GPT,如同下面的文本所示。
\n
You are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow.
\n\n常见的范式有:
\n回想一下🤔,当我们和GPT之类的产品进行交互时,我们的交互方式大致上有两类:\n举个例子,当我需要让GPT帮我写一个算法时,我可能会:
\n\n\n“我需要你写一段代码,这段代码第一行是
\ndef
,然后是函数名,然后是3个参数,然后是四行函数体。函数体中需要有return
。它第一行是……最后一行是……。”
这是一种典型的命令式交互,非常好使。
\n\n\n“直接说,我需要一个算法,这个算法需要满足以下要求:……”
\n
这是一种典型的声明式交互,主要关注结果的描述和需求,而不需要详细说明如何达到这个结果。
\n警告
\n声明式交互在代码实现上具有更大的风险,尤其是你缺乏对代码的深入理解时,比如李逵和李鬼:
\n\n重要
\n这里最核心的逻辑是,你和GPT之间的信息越一致,那么你得到的代码就越符合你的预期。
\n正是基于这个逻辑,我们才需要在第二步进行伪代码交互。
\n我提供一个比较极端的例子,假设你想要一个按照一定规则拆分矩阵的代码,并把结果存在你的类中,你和GPT的交互的伪代码如下:
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows
\n\n根据我的观察,如果你写了伪代码,在GPT的帮助下,它既可以是python也可以是C++,甚至可以是Java。它既可以是面向对象的,也可以是函数式的。你可以把更多的时间花在思考上,而不是写代码上。 算法上的革新带来的进步,远比你写代码tricks带来的进步要大。
\n再者,正如笑容不会消失,笑容只会从一个人的脸上转移到另一个人的脸上。复杂性也是一样的,复杂性不会消失,复杂性只会从这里转移到那里。在这里,我们可以尝试把复杂性转移到机器上。很多优秀的工程师都有这样的习惯,把代码写的像诗一样的优雅,充满了各种隐喻、抽象。也正是这个原因,维护自然语言的伪代码的复杂性,远比你维护代码的复杂性要低。
\n提示
\n诚然,大语言模型的技术一直在进步,但是,受限于其上下文能力,基于效率上的考虑,我们应该尝试把真实的工程进行模块化、结构化。
\n\n\nGPT先天的适合增量更新的模式,为了春分利用这一点,需要作为“架构师”的你首先对你的工程进行定义。
\n
提示
\n确保模块间的解耦,有些时候你会想用不同的大模型来完成不同的模块。
\n\n\n你可以参考下面的步骤来定义你的模块。
\n
提示
\n我利用刚刚例子中的伪代码和拆分模块的思想制作了promote,你可以在这里看到完整的上下文信息。
\n\n\n我创建了chatGPT(o1-mini模型)分享链接,点击链接,你可以在这里看到一个完整的例子。
\n
重要
\n1. 复制对GPT输入代码风格化的要求
\n--->>> 2. 编写包含你所有的要求和想法的伪代码
\n--------->>> 3. 拆分伪代码,分模块实现
\n\n\n具体的(注意代码块右侧的复制按钮):
\n
这里同上
\nYou are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow.
\n\n这里同上
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows”。 最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。
\n\n这里我们分块实现
\n我构思了一个矩阵拆分的算法,我定义我的模块有:0 验证用户的输入是否合适我们的拆分方法:如是否可以进行因式分解;1 生成矩阵;2 对矩阵进行拆分;3 把拆分后的矩阵和原有的矩阵在一张图片上叠加显示,着重显示拆分矩阵的边界。注意:技术选型为python3。我定义了第2部分的伪代码,代码如下“
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows
\n\n”。最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。
\n这里上面的提示词有些问题,我没有严格的定义可视化的方式,于是出现了问题。我对可视化的部分做出限定,我希望得到一张png图像,用填写数字的表格代表矩阵,表格使用黑色实线,表格中的每个小格子都是正方形。矩阵被切分的接缝处使用红色粗实线进行区分。
\n我在运行这段代码的时候遇到了问题,详细的上下文信息是“
\n% python test.py
\n\nMatrix Splitting Algorithm with Enhanced Visualization\n------------------------------------------------------\nEnter the number of rows and columns (e.g., '8 12'): 80 12\nGenerated matrix of size 80x12.\nRow factor: 4, Column factor: 4\nMatrix split into 20 row-wise submatrices.\nTotal small matrices after horizontal split: 60\nGenerated seam matrices for columns: 20 sets.\nTraceback (most recent call last):\n File \"/Users/hughes/docs/test.py\", line 195, in <module>\n main()\n File \"/Users/hughes/docs/test.py\", line 191, in main\n splitter.split_matrix()\n File \"/Users/hughes/docs/test.py\", line 99, in split_matrix\n seam_matrix = np.vstack((top_matrix[-1, :].reshape(1, -1), bottom_matrix[0, :].reshape(1, -1)))\n ~~~~~~~~~~^^^^^^^\nIndexError: index -1 is out of bounds for axis 0 with size 0”
\n\n非常好👍,下面我们再对可视化的部分进行功能点的新增,刚刚我们的代码实现了对于按列拆分时的可视化,我们在最终的图像上增加按行拆分矩阵时的线,用绿色的粗实线来表示。在绘图的部分外部套一个tqdm的进度展示,便于在终端中查阅进度。
\n#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\n\"\"\"\nMatrix Splitting Algorithm with Enhanced Visualization\n\nThis script captures user input for matrix dimensions, validates the input,\ngenerates a matrix, splits it based on factorization, and visualizes the\noriginal and split matrices with clearly defined grid lines and highlighted\nsplit boundaries. The final visualization is saved as a PNG image.\n\nEnhancements:\n1. Added green thick lines to represent row splits.\n2. Incorporated tqdm progress bars to monitor plotting progress.\n\nAuthor: OpenAI ChatGPT\nDate: 2024-11-08\n\"\"\"\n\nimport sys\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.patches import Rectangle\nfrom tqdm import tqdm # Import tqdm for progress bars\n\nclass MatrixSplitter:\n def __init__(self, rows, cols):\n \"\"\"\n Initializes the MatrixSplitter with the specified number of rows and columns.\n\n Parameters:\n rows (int): Number of rows in the matrix.\n cols (int): Number of columns in the matrix.\n \"\"\"\n self.rows = rows\n self.cols = cols\n self.matrix = None\n self.small_matrices = [] # 2D list: small_matrices[i][j]\n self.seam_matrices_cols = []\n self.seam_matrices_rows = []\n\n def smallest_factor_greater_than_three(self, n):\n \"\"\"\n Finds the smallest factor of n that is greater than three.\n\n Parameters:\n n (int): The number to find a factor for.\n\n Returns:\n int: The smallest factor greater than three, or n if no such factor exists.\n \"\"\"\n for i in range(4, n + 1):\n if n % i == 0:\n return i\n return n\n\n def generate_matrix(self):\n \"\"\"\n Generates a matrix with random integers between 0 and 99.\n \"\"\"\n self.matrix = np.random.randint(0, 100, size=(self.rows, self.cols))\n print(f\"Generated matrix of size {self.rows}x{self.cols}.\")\n\n def split_matrix(self):\n \"\"\"\n Splits the matrix into smaller matrices based on factorization.\n \"\"\"\n # Find factors\n row_factor = self.smallest_factor_greater_than_three(self.rows)\n col_factor = self.smallest_factor_greater_than_three(self.cols)\n print(f\"Row factor: {row_factor}, Column factor: {col_factor}\")\n\n # Calculate number of splits\n num_row_splits = self.rows // row_factor\n num_col_splits = self.cols // col_factor\n\n # First split: Vertical (rows)\n row_split = np.array_split(self.matrix, num_row_splits, axis=0)\n print(f\"Matrix split into {len(row_split)} row-wise submatrices.\")\n\n # Further split: Horizontal (columns)\n # Convert small_matrices to a 2D list\n for sub_matrix in row_split:\n cols_split = np.array_split(sub_matrix, num_col_splits, axis=1)\n self.small_matrices.append(cols_split)\n total_small_matrices = len(self.small_matrices) * num_col_splits\n print(f\"Total small matrices after horizontal split: {total_small_matrices}\")\n\n # Second split: Seam matrices for columns\n for sub_matrix in row_split:\n row_seams = []\n for j in range(num_col_splits - 1):\n last_col = sub_matrix[:, (j + 1) * col_factor - 1].reshape(-1, 1)\n next_col = sub_matrix[:, (j + 1) * col_factor].reshape(-1, 1)\n seam_matrix = np.hstack((last_col, next_col))\n row_seams.append(seam_matrix)\n self.seam_matrices_cols.append(row_seams)\n print(f\"Generated seam matrices for columns: {len(self.seam_matrices_cols)} sets.\")\n\n # Third split: Seam matrices for rows\n for i in range(num_row_splits - 1):\n row_seams = []\n for j in range(num_col_splits):\n # Access small_matrices as a 2D list\n top_matrix = self.small_matrices[i][j]\n bottom_matrix = self.small_matrices[i + 1][j]\n # Get the last row of top_matrix and first row of bottom_matrix\n top_last_row = top_matrix[-1, :].reshape(1, -1)\n bottom_first_row = bottom_matrix[0, :].reshape(1, -1)\n seam_matrix = np.vstack((top_last_row, bottom_first_row))\n row_seams.append(seam_matrix)\n self.seam_matrices_rows.append(row_seams)\n print(f\"Generated seam matrices for rows: {len(self.seam_matrices_rows)} sets.\")\n\n def visualize_splits(self, output_filename=\"matrix_split.png\"):\n \"\"\"\n Visualizes the original and split matrices as a numbered grid with black grid lines,\n red thick lines for column splits, and green thick lines for row splits.\n The visualization is saved as a PNG image.\n\n Parameters:\n output_filename (str): The filename for the saved PNG image.\n \"\"\"\n fig, ax = plt.subplots(figsize=(self.cols, self.rows))\n ax.set_xlim(0, self.cols)\n ax.set_ylim(0, self.rows)\n ax.set_xticks(np.arange(0, self.cols + 1, 1))\n ax.set_yticks(np.arange(0, self.rows + 1, 1))\n ax.set_xticklabels([])\n ax.set_yticklabels([])\n ax.grid(which='both', color='black', linewidth=1)\n\n # Invert y-axis to have the first row at the top\n ax.invert_yaxis()\n\n # Add numbers to each cell with a progress bar\n total_cells = self.rows * self.cols\n with tqdm(total=total_cells, desc=\"Plotting cells\", unit=\"cell\") as pbar:\n for i in range(self.rows):\n for j in range(self.cols):\n cell_value = self.matrix[i, j]\n ax.text(j + 0.5, i + 0.5, str(cell_value),\n va='center', ha='center', fontsize=8)\n pbar.update(1)\n\n # Highlight split boundaries with red thick lines (columns) and green thick lines (rows)\n row_factor = self.smallest_factor_greater_than_three(self.rows)\n col_factor = self.smallest_factor_greater_than_three(self.cols)\n\n # Horizontal split lines (rows) - Green\n with tqdm(total=self.rows // row_factor - 1, desc=\"Drawing row splits\", unit=\"split\") as pbar:\n for i in range(1, self.rows // row_factor):\n ax.axhline(i * row_factor, color='green', linewidth=2)\n pbar.update(1)\n\n # Vertical split lines (columns) - Red\n with tqdm(total=self.cols // col_factor - 1, desc=\"Drawing column splits\", unit=\"split\") as pbar:\n for j in range(1, self.cols // col_factor):\n ax.axvline(j * col_factor, color='red', linewidth=2)\n pbar.update(1)\n\n # Remove whitespace and axes\n plt.axis('off')\n plt.tight_layout()\n\n # Save the figure\n plt.savefig(output_filename, dpi=300, bbox_inches='tight')\n plt.close()\n print(f\"Visualization saved as '{output_filename}'.\")\n\ndef validate_input(input_str):\n \"\"\"\n Validates that the input string contains two integers greater than or equal to 4.\n\n Parameters:\n input_str (str): The input string containing two numbers.\n\n Returns:\n tuple: A tuple containing two integers (rows, cols).\n\n Raises:\n ValueError: If input is invalid.\n \"\"\"\n try:\n parts = input_str.strip().split()\n if len(parts) != 2:\n raise ValueError(\"Please enter exactly two numbers separated by space.\")\n rows, cols = map(int, parts)\n if rows < 4 or cols < 4:\n raise ValueError(\"Both dimensions must be at least 4.\")\n return rows, cols\n except Exception as e:\n raise ValueError(f\"Invalid input: {e}\")\n\ndef main():\n \"\"\"\n Main function to execute the matrix splitting algorithm.\n \"\"\"\n print(\"Matrix Splitting Algorithm with Enhanced Visualization\")\n print(\"------------------------------------------------------\")\n try:\n user_input = input(\"Enter the number of rows and columns (e.g., '8 12'): \")\n rows, cols = validate_input(user_input)\n except ValueError as ve:\n print(ve)\n sys.exit(1)\n\n splitter = MatrixSplitter(rows, cols)\n splitter.generate_matrix()\n splitter.split_matrix()\n splitter.visualize_splits()\n\nif __name__ == \"__main__\":\n main()
\n\n\n\n\n仔细看看下面的代码,这就是你加上o1-mini的能力
\n
\n\n我必须在这里重申 “AI放大了人类的能力边界”,代码的最终结果极大的取决于 “人的思考” 的质量。
\n
在这里,我推荐书籍《人月神话》wiki,虽然此书是写于1975年,但数十年来多次重印。书中对软件工程的思考,对软件开发中人的因素的思考,非常值得阅读。
\nover
\n","contentStripped":"1. 复制对GPT输入代码风格化的要求
\n--->>> 2. 编写包含你所有的要求和想法的伪代码
\n--------->>> 3. 拆分伪代码,分模块实现
\n\n\n本文通过几个例子展示了用GPT敲代码的几个模式,您需要确保您的键盘具有Ctrl键、C键、V键。
\n
\n\n受文本长度限制,本文尽量不对任何内容的驱动原理做出解释。
\n
注
\n重要
\nAI放大了人类的能力边界,但社会生活的主体依然是自然人。
\n\n\n跟我复制
\n
\n\n如果你有一些类似于“整洁代码”的偏好,或者你有明确的编程习惯,请在进行代码产出时,明确告诉GPT,如同下面的文本所示。
\n
You are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow.
\n\n常见的范式有:
\n回想一下🤔,当我们和GPT之类的产品进行交互时,我们的交互方式大致上有两类:\n举个例子,当我需要让GPT帮我写一个算法时,我可能会:
\n\n\n“我需要你写一段代码,这段代码第一行是
\ndef
,然后是函数名,然后是3个参数,然后是四行函数体。函数体中需要有return
。它第一行是……最后一行是……。”
这是一种典型的命令式交互,非常好使。
\n\n\n“直接说,我需要一个算法,这个算法需要满足以下要求:……”
\n
这是一种典型的声明式交互,主要关注结果的描述和需求,而不需要详细说明如何达到这个结果。
\n警告
\n声明式交互在代码实现上具有更大的风险,尤其是你缺乏对代码的深入理解时,比如李逵和李鬼:
\n\n重要
\n这里最核心的逻辑是,你和GPT之间的信息越一致,那么你得到的代码就越符合你的预期。
\n正是基于这个逻辑,我们才需要在第二步进行伪代码交互。
\n我提供一个比较极端的例子,假设你想要一个按照一定规则拆分矩阵的代码,并把结果存在你的类中,你和GPT的交互的伪代码如下:
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows
\n\n根据我的观察,如果你写了伪代码,在GPT的帮助下,它既可以是python也可以是C++,甚至可以是Java。它既可以是面向对象的,也可以是函数式的。你可以把更多的时间花在思考上,而不是写代码上。 算法上的革新带来的进步,远比你写代码tricks带来的进步要大。
\n再者,正如笑容不会消失,笑容只会从一个人的脸上转移到另一个人的脸上。复杂性也是一样的,复杂性不会消失,复杂性只会从这里转移到那里。在这里,我们可以尝试把复杂性转移到机器上。很多优秀的工程师都有这样的习惯,把代码写的像诗一样的优雅,充满了各种隐喻、抽象。也正是这个原因,维护自然语言的伪代码的复杂性,远比你维护代码的复杂性要低。
\n提示
\n诚然,大语言模型的技术一直在进步,但是,受限于其上下文能力,基于效率上的考虑,我们应该尝试把真实的工程进行模块化、结构化。
\n\n\nGPT先天的适合增量更新的模式,为了春分利用这一点,需要作为“架构师”的你首先对你的工程进行定义。
\n
提示
\n确保模块间的解耦,有些时候你会想用不同的大模型来完成不同的模块。
\n\n\n你可以参考下面的步骤来定义你的模块。
\n
提示
\n我利用刚刚例子中的伪代码和拆分模块的思想制作了promote,你可以在这里看到完整的上下文信息。
\n\n\n我创建了chatGPT(o1-mini模型)分享链接,点击链接,你可以在这里看到一个完整的例子。
\n
重要
\n1. 复制对GPT输入代码风格化的要求
\n--->>> 2. 编写包含你所有的要求和想法的伪代码
\n--------->>> 3. 拆分伪代码,分模块实现
\n\n\n具体的(注意代码块右侧的复制按钮):
\n
这里同上
\nYou are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow.
\n\n这里同上
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows”。 最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。
\n\n这里我们分块实现
\n我构思了一个矩阵拆分的算法,我定义我的模块有:0 验证用户的输入是否合适我们的拆分方法:如是否可以进行因式分解;1 生成矩阵;2 对矩阵进行拆分;3 把拆分后的矩阵和原有的矩阵在一张图片上叠加显示,着重显示拆分矩阵的边界。注意:技术选型为python3。我定义了第2部分的伪代码,代码如下“
\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows
\n\n”。最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。
\n这里上面的提示词有些问题,我没有严格的定义可视化的方式,于是出现了问题。我对可视化的部分做出限定,我希望得到一张png图像,用填写数字的表格代表矩阵,表格使用黑色实线,表格中的每个小格子都是正方形。矩阵被切分的接缝处使用红色粗实线进行区分。
\n我在运行这段代码的时候遇到了问题,详细的上下文信息是“
\n% python test.py
\n\nMatrix Splitting Algorithm with Enhanced Visualization\n------------------------------------------------------\nEnter the number of rows and columns (e.g., '8 12'): 80 12\nGenerated matrix of size 80x12.\nRow factor: 4, Column factor: 4\nMatrix split into 20 row-wise submatrices.\nTotal small matrices after horizontal split: 60\nGenerated seam matrices for columns: 20 sets.\nTraceback (most recent call last):\n File \"/Users/hughes/docs/test.py\", line 195, in <module>\n main()\n File \"/Users/hughes/docs/test.py\", line 191, in main\n splitter.split_matrix()\n File \"/Users/hughes/docs/test.py\", line 99, in split_matrix\n seam_matrix = np.vstack((top_matrix[-1, :].reshape(1, -1), bottom_matrix[0, :].reshape(1, -1)))\n ~~~~~~~~~~^^^^^^^\nIndexError: index -1 is out of bounds for axis 0 with size 0”
\n\n非常好👍,下面我们再对可视化的部分进行功能点的新增,刚刚我们的代码实现了对于按列拆分时的可视化,我们在最终的图像上增加按行拆分矩阵时的线,用绿色的粗实线来表示。在绘图的部分外部套一个tqdm的进度展示,便于在终端中查阅进度。
\n#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\n\"\"\"\nMatrix Splitting Algorithm with Enhanced Visualization\n\nThis script captures user input for matrix dimensions, validates the input,\ngenerates a matrix, splits it based on factorization, and visualizes the\noriginal and split matrices with clearly defined grid lines and highlighted\nsplit boundaries. The final visualization is saved as a PNG image.\n\nEnhancements:\n1. Added green thick lines to represent row splits.\n2. Incorporated tqdm progress bars to monitor plotting progress.\n\nAuthor: OpenAI ChatGPT\nDate: 2024-11-08\n\"\"\"\n\nimport sys\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.patches import Rectangle\nfrom tqdm import tqdm # Import tqdm for progress bars\n\nclass MatrixSplitter:\n def __init__(self, rows, cols):\n \"\"\"\n Initializes the MatrixSplitter with the specified number of rows and columns.\n\n Parameters:\n rows (int): Number of rows in the matrix.\n cols (int): Number of columns in the matrix.\n \"\"\"\n self.rows = rows\n self.cols = cols\n self.matrix = None\n self.small_matrices = [] # 2D list: small_matrices[i][j]\n self.seam_matrices_cols = []\n self.seam_matrices_rows = []\n\n def smallest_factor_greater_than_three(self, n):\n \"\"\"\n Finds the smallest factor of n that is greater than three.\n\n Parameters:\n n (int): The number to find a factor for.\n\n Returns:\n int: The smallest factor greater than three, or n if no such factor exists.\n \"\"\"\n for i in range(4, n + 1):\n if n % i == 0:\n return i\n return n\n\n def generate_matrix(self):\n \"\"\"\n Generates a matrix with random integers between 0 and 99.\n \"\"\"\n self.matrix = np.random.randint(0, 100, size=(self.rows, self.cols))\n print(f\"Generated matrix of size {self.rows}x{self.cols}.\")\n\n def split_matrix(self):\n \"\"\"\n Splits the matrix into smaller matrices based on factorization.\n \"\"\"\n # Find factors\n row_factor = self.smallest_factor_greater_than_three(self.rows)\n col_factor = self.smallest_factor_greater_than_three(self.cols)\n print(f\"Row factor: {row_factor}, Column factor: {col_factor}\")\n\n # Calculate number of splits\n num_row_splits = self.rows // row_factor\n num_col_splits = self.cols // col_factor\n\n # First split: Vertical (rows)\n row_split = np.array_split(self.matrix, num_row_splits, axis=0)\n print(f\"Matrix split into {len(row_split)} row-wise submatrices.\")\n\n # Further split: Horizontal (columns)\n # Convert small_matrices to a 2D list\n for sub_matrix in row_split:\n cols_split = np.array_split(sub_matrix, num_col_splits, axis=1)\n self.small_matrices.append(cols_split)\n total_small_matrices = len(self.small_matrices) * num_col_splits\n print(f\"Total small matrices after horizontal split: {total_small_matrices}\")\n\n # Second split: Seam matrices for columns\n for sub_matrix in row_split:\n row_seams = []\n for j in range(num_col_splits - 1):\n last_col = sub_matrix[:, (j + 1) * col_factor - 1].reshape(-1, 1)\n next_col = sub_matrix[:, (j + 1) * col_factor].reshape(-1, 1)\n seam_matrix = np.hstack((last_col, next_col))\n row_seams.append(seam_matrix)\n self.seam_matrices_cols.append(row_seams)\n print(f\"Generated seam matrices for columns: {len(self.seam_matrices_cols)} sets.\")\n\n # Third split: Seam matrices for rows\n for i in range(num_row_splits - 1):\n row_seams = []\n for j in range(num_col_splits):\n # Access small_matrices as a 2D list\n top_matrix = self.small_matrices[i][j]\n bottom_matrix = self.small_matrices[i + 1][j]\n # Get the last row of top_matrix and first row of bottom_matrix\n top_last_row = top_matrix[-1, :].reshape(1, -1)\n bottom_first_row = bottom_matrix[0, :].reshape(1, -1)\n seam_matrix = np.vstack((top_last_row, bottom_first_row))\n row_seams.append(seam_matrix)\n self.seam_matrices_rows.append(row_seams)\n print(f\"Generated seam matrices for rows: {len(self.seam_matrices_rows)} sets.\")\n\n def visualize_splits(self, output_filename=\"matrix_split.png\"):\n \"\"\"\n Visualizes the original and split matrices as a numbered grid with black grid lines,\n red thick lines for column splits, and green thick lines for row splits.\n The visualization is saved as a PNG image.\n\n Parameters:\n output_filename (str): The filename for the saved PNG image.\n \"\"\"\n fig, ax = plt.subplots(figsize=(self.cols, self.rows))\n ax.set_xlim(0, self.cols)\n ax.set_ylim(0, self.rows)\n ax.set_xticks(np.arange(0, self.cols + 1, 1))\n ax.set_yticks(np.arange(0, self.rows + 1, 1))\n ax.set_xticklabels([])\n ax.set_yticklabels([])\n ax.grid(which='both', color='black', linewidth=1)\n\n # Invert y-axis to have the first row at the top\n ax.invert_yaxis()\n\n # Add numbers to each cell with a progress bar\n total_cells = self.rows * self.cols\n with tqdm(total=total_cells, desc=\"Plotting cells\", unit=\"cell\") as pbar:\n for i in range(self.rows):\n for j in range(self.cols):\n cell_value = self.matrix[i, j]\n ax.text(j + 0.5, i + 0.5, str(cell_value),\n va='center', ha='center', fontsize=8)\n pbar.update(1)\n\n # Highlight split boundaries with red thick lines (columns) and green thick lines (rows)\n row_factor = self.smallest_factor_greater_than_three(self.rows)\n col_factor = self.smallest_factor_greater_than_three(self.cols)\n\n # Horizontal split lines (rows) - Green\n with tqdm(total=self.rows // row_factor - 1, desc=\"Drawing row splits\", unit=\"split\") as pbar:\n for i in range(1, self.rows // row_factor):\n ax.axhline(i * row_factor, color='green', linewidth=2)\n pbar.update(1)\n\n # Vertical split lines (columns) - Red\n with tqdm(total=self.cols // col_factor - 1, desc=\"Drawing column splits\", unit=\"split\") as pbar:\n for j in range(1, self.cols // col_factor):\n ax.axvline(j * col_factor, color='red', linewidth=2)\n pbar.update(1)\n\n # Remove whitespace and axes\n plt.axis('off')\n plt.tight_layout()\n\n # Save the figure\n plt.savefig(output_filename, dpi=300, bbox_inches='tight')\n plt.close()\n print(f\"Visualization saved as '{output_filename}'.\")\n\ndef validate_input(input_str):\n \"\"\"\n Validates that the input string contains two integers greater than or equal to 4.\n\n Parameters:\n input_str (str): The input string containing two numbers.\n\n Returns:\n tuple: A tuple containing two integers (rows, cols).\n\n Raises:\n ValueError: If input is invalid.\n \"\"\"\n try:\n parts = input_str.strip().split()\n if len(parts) != 2:\n raise ValueError(\"Please enter exactly two numbers separated by space.\")\n rows, cols = map(int, parts)\n if rows < 4 or cols < 4:\n raise ValueError(\"Both dimensions must be at least 4.\")\n return rows, cols\n except Exception as e:\n raise ValueError(f\"Invalid input: {e}\")\n\ndef main():\n \"\"\"\n Main function to execute the matrix splitting algorithm.\n \"\"\"\n print(\"Matrix Splitting Algorithm with Enhanced Visualization\")\n print(\"------------------------------------------------------\")\n try:\n user_input = input(\"Enter the number of rows and columns (e.g., '8 12'): \")\n rows, cols = validate_input(user_input)\n except ValueError as ve:\n print(ve)\n sys.exit(1)\n\n splitter = MatrixSplitter(rows, cols)\n splitter.generate_matrix()\n splitter.split_matrix()\n splitter.visualize_splits()\n\nif __name__ == \"__main__\":\n main()
\n\n\n\n\n仔细看看下面的代码,这就是你加上o1-mini的能力
\n
\n\n我必须在这里重申 “AI放大了人类的能力边界”,代码的最终结果极大的取决于 “人的思考” 的质量。
\n
在这里,我推荐书籍《人月神话》wiki,虽然此书是写于1975年,但数十年来多次重印。书中对软件工程的思考,对软件开发中人的因素的思考,非常值得阅读。
\nover
\n","tagOpen":"","tagClose":""},"script":null,"scriptSetup":null,"scripts":[],"styles":[],"customBlocks":[]},"content":"## 快速实现\n\n- **1. 复制对GPT输入代码风格化的要求**\n\n- **--->>> 2. 编写包含你所有的要求和想法的伪代码**\n\n- **--------->>> 3. 拆分伪代码,分模块实现**\n\n### 完整示例\n[点击看chatgpt o1-mini模型的开发示例](https://chatgpt.com/share/66e56444-484d-484d-984d-484d484d484d)\n\n\n## 引言\n\n> 本文通过几个例子展示了用GPT敲代码的几个模式,您需要确保您的键盘具有Ctrl键、C键、V键。\n\n> 受文本长度限制,本文尽量不对任何内容的驱动原理做出解释。\n\n#### 读者应该明确\n> [!note]\n> 1. **工程控制论正在推动电子计算机技术革命的深入。这样一个现实已经来到了人类面前: 由电子计算机和机器智能装备起来的人,已经成为更有作为、更高超的人! ———钱学森 《工程控制论·序言》**\n> 2. **君子不器。 ———孔子《论语·为政篇》**\n> 3. **[“值得怀疑的是,一切已有的机械发明,是否减轻了任何人每天的辛劳。”](https://www.marxists.org/chinese/marx-engels-2/44/019.htm) ———约翰·斯图亚特·穆勒《政治经济学原理》**\n\n::: important 重要\nAI放大了人类的能力边界,但社会生活的主体依然是自然人。\n:::\n\n## 第一部分:对GPT输入代码风格化的要求\n\n> 跟我复制\n\n> 如果你有一些类似于“整洁代码”的偏好,或者你有明确的编程习惯,请在进行代码产出时,明确告诉GPT,如同下面的文本所示。\n\n```txt :collapsed-lines=8\nYou are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow. \n```\n\n## 第二部分:把你的想法转换为伪代码或类似的逻辑描述\n\n### 📏范式\n\n常见的范式有:\n- ==命令式编程(Imperative Programming)==\n 程序由一系列的命令或语句组成,计算机按照这些命令执行操作。这是最早也是最基本的编程范式。典型代表:C 和 Java\n - ==声明式编程(Declarative Programming)==:程序员只需要描述他们想要的结果,而不需要详细说明如何达到这个结果。典型代表:SQL 和 HTML \n - ==面向对象编程(Object-Oriented Programming)==:程序被组织成对象,每个对象都包含数据和操作数据的方法。面向对象编程强调的是数据抽象和封装,以及对象之间的交互。典型代表:Java 和 Python\n\n### 为什么需要伪代码?\n\n回想一下🤔,当我们和GPT之类的产品进行交互时,我们的交互方式大致上有两类:\n举个例子,当我需要让GPT帮我写一个算法时,我可能会:\n#### 第一种交互方式\n> “我需要你写一段代码,这段代码第一行是`def`,然后是函数名,然后是3个参数,然后是四行函数体。函数体中需要有`return`。它第一行是……最后一行是……。”\n\n这是一种典型的命令式交互,非常好使。\n\n#### 第二种交互方式\n> “直接说,我需要一个算法,这个算法需要满足以下要求:……”\n\n这是一种典型的声明式交互,主要关注结果的描述和需求,而不需要详细说明如何达到这个结果。\n\n::: warning 警告\n\n声明式交互在代码实现上具有更大的风险,尤其是==你缺乏对代码的深入理解时==,比如李逵和李鬼:\n\n![Alt text](http://k.sinaimg.cn/n/sinacn/w500h229/20180102/7226-fyqefvx1303978.jpg/w700d1q75cms.jpg?by=cms_fixed_width)\n:::\n\n::: important 重要\n\n- 这里最**核心的逻辑**是,你和GPT之间的信息越一致,那么你得到的代码就越符合你的预期。\n\n- 正是基于这个逻辑,我们才需要在第二步进行==伪代码交互==。\n\n:::\n\n#### 伪代码的交互\n\n我提供一个比较极端的例子,假设你想要一个按照一定规则拆分矩阵的代码,并把结果存在你的类中,你和GPT的交互的伪代码如下:\n\n```python\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows\n```\n\n::: tip 提示\n### 🙋好,那么好,这时候聪明的你就要问了:\n> # “我都写到这种程度了,为什么我不亲自写一遍?好像工作量是差不多的。”\n\n:::\n\n根据我的观察,如果你写了伪代码,在GPT的帮助下,它既可以是python也可以是C++,甚至可以是Java。它既可以是面向对象的,也可以是函数式的。==你可以把更多的时间花在思考上,而不是写代码上。== 算法上的革新带来的进步,远比你写代码tricks带来的进步要大。\n\n再者,正如笑容不会消失,笑容只会从一个人的脸上转移到另一个人的脸上。复杂性也是一样的,复杂性不会消失,复杂性只会从这里转移到那里。在这里,我们可以尝试把复杂性转移到机器上。很多优秀的工程师都有这样的习惯,把代码写的像诗一样的优雅,充满了各种隐喻、抽象。也正是这个原因,维护自然语言的伪代码的复杂性,远比你维护代码的复杂性要低。\n\n## 第三部分:怎么让GPT整点复杂的东西?\n\n::: tip 提示\n诚然,大语言模型的技术一直在进步,但是,受限于其上下文能力,基于效率上的考虑,我们应该尝试把真实的工程进行模块化、结构化。\n:::\n\n### 这一点和完成一个大型工程一摸一样\n\n> GPT先天的适合增量更新的模式,为了春分利用这一点,需要作为“架构师”的你首先对你的工程进行定义。\n\n::: tip 提示\n确保模块间的解耦,有些时候你会想用不同的大模型来完成不同的模块。\n:::\n\n> 你可以参考下面的步骤来定义你的模块。\n\n### **3.1 定义互相解耦的模块**\n1. **模块划分原则**\n - 高内聚低耦合\n - 明确的接口和责任\n2. **识别关键功能模块**\n - 功能分解的方法\n - 示例:将一个Web应用划分为前端、后端、数据库等模块\n3. **接口设计**\n - 模块间通信的标准\n - 使用API和协议确保模块独立性\n\n### **3.2 模块化的实施步骤**\n1. **需求分析与功能分解**\n - 收集和分析项目需求\n - 将需求转化为功能模块\n2. **模块设计与规划**\n - 为每个模块制定详细设计\n - 确定模块之间的依赖关系\n3. **逐个模块的开发与测试**\n - 按照规划顺序开发模块\n - 独立测试每个模块的功能和性能\n4. **集成与系统测试**\n - 将各模块集成到整体系统中\n - 进行系统级别的测试和优化\n\n### **3.3 利用GPT进行模块化开发**\n\n#### 1. 分块粘贴伪代码\n\n## 作为结论\n\n### 实践:让我们在这里引入一个具体的例子\n\n::: tip 提示\n我利用刚刚例子中的伪代码和拆分模块的思想制作了promote,你可以在这里看到完整的上下文信息。\n> 我创建了chatGPT(o1-mini模型)[分享链接](https://chatgpt.com/share/66e56444-484d-484d-984d-484d484d484d),点击链接,你可以在这里看到一个完整的例子。\n:::\n\n::: important 重要\n\n### 我们实际上做了什么?\n\n- **1. 复制对GPT输入代码风格化的要求**\n\n- **--->>> 2. 编写包含你所有的要求和想法的伪代码**\n\n- **--------->>> 3. 拆分伪代码,分模块实现**\n\n:::\n\n> ==具体的==(注意代码块右侧的复制按钮):\n::: tabs\n\n@tab 1/5 复制\n\n==这里同上==\n```txt :collapsed-lines=8\nYou are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions:\n\nBreak Down the Coding Task:\n\nBegin by applying Chain of Thought (CoT) reasoning to decompose the programming task into logical, manageable components. Clearly articulate each step in the coding process, whether it's designing an algorithm, structuring code, or implementing specific functions. Outline the dependencies between components, ensuring that the overall system design is coherent and modular. Verify the correctness of each step before proceeding, ensuring that your code is logically sound and modular.\n\nRationalize Each Coding Decision:\n\nAs you develop the code, use Step-by-Step Rationalization (STaR) to provide clear, logical justifications for every decision made during the coding process. Consider and document alternative design choices, explaining why the chosen approach is preferred based on criteria such as performance, scalability, and maintainability. Ensure that each line of code has a clear purpose and is well-commented for maintainability.\n\nOptimize Code for Efficiency and Reliability:\n\nIncorporate A Search principles* to evaluate and optimize the efficiency of your code. Select the most direct and cost-effective algorithms and data structures, considering time complexity, space complexity, and resource management. Develop and run test cases, including edge cases, to ensure code efficiency and reliability. Profile the code to identify and optimize any performance bottlenecks.\n\nConsider and Evaluate Multiple Code Solutions:\n\nLeverage Tree of Thoughts (ToT) to explore different coding approaches and solutions in parallel. Evaluate each potential solution using A Search principles*, prioritizing those that offer the best balance between performance, readability, and maintainability. Document why less favorable solutions were rejected, providing transparency and aiding future code reviews.\n\nSimulate Adaptive Learning in Coding:\n\nReflect on your coding decisions throughout the session as if you were learning from each outcome. Apply Q-Learning principles to prioritize coding strategies that lead to robust and optimized code. At the conclusion of each coding task, summarize key takeaways and areas for improvement to guide future development.\n\nContinuously Monitor and Refine Your Coding Process:\n\nEngage in Process Monitoring to continuously assess the progress of your coding task. Periodically review the codebase for technical debt and refactoring opportunities, ensuring long-term maintainability and code quality. Ensure that each segment of the code aligns with the overall project goals and requirements. Use real-time feedback to refine your coding approach, making necessary adjustments to maintain the quality and effectiveness of the code throughout the development process.\n\nIncorporate Security Best Practices:\n\nApply security best practices, including input validation, encryption, and secure coding techniques, to safeguard against vulnerabilities. Ensure that the code is robust against common security threats.\n\nHighlight Code Readability:\n\nPrioritize code readability by using clear variable names, consistent formatting, and logical organization. Ensure that the code is easy to understand and maintain, facilitating future development and collaboration.\n\nInclude Collaboration Considerations:\n\nConsider how the code will be used and understood by other developers. Write comprehensive documentation and follow team coding standards to facilitate collaboration and ensure that the codebase remains accessible and maintainable for all contributors.\n\nFinal Instruction:\n\nBy following these instructions, you will ensure that your coding approach is methodical, well-reasoned, and optimized for technical precision and efficiency. Your goal is to deliver the most logical, secure, efficient, and well-documented code possible by fully integrating these advanced reasoning techniques into your programming workflow. \n```\n\n@tab 2/5 编写伪代码\n\n==这里同上==\n\n```python :collapsed-lines=10\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows”。 最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。\n```\n\n@tab:active 3/5 先主体\n\n==这里我们分块实现==\n\n#### **主体部分**\n\n我构思了一个矩阵拆分的算法,我定义我的模块有:0 验证用户的输入是否合适我们的拆分方法:如是否可以进行因式分解;1 生成矩阵;2 对矩阵进行拆分;3 把拆分后的矩阵和原有的矩阵在一张图片上叠加显示,着重显示拆分矩阵的边界。注意:技术选型为python3。我定义了第2部分的伪代码,代码如下“\n\n```python :collapsed-lines=5\n定义函数 ():\n\n 寻找矩阵的因数(n):\n 对于 i 从 4 到 n(包含 n):\n 如果 n 能被 i 整除:\n 返回 i\n 返回 n # 如果没有找到因数,返回 n 本身\n\n 获取矩阵的行数和列数:\n rows, cols = 矩阵的形状\n\n 找到大于 3 的最小因数:\n row_factor = smallest_factor_greater_than_three(rows)\n col_factor = smallest_factor_greater_than_three(cols)\n\n # 第一拆分方法:按因数拆分行和列\n 将矩阵按行拆分为多个子矩阵:\n row_split = 按 row_factor 将矩阵垂直拆分\n 将每个子矩阵按列拆分为更小的矩阵:\n small_matrices = 对于每个 sub_matrix 在 row_split 中,按 col_factor 水平拆分\n\n # 第二拆分方法:取相邻列的接缝区域\n 初始化 seam_matrices_cols 为一个空列表\n 对于 每个 row_matrices 在 small_matrices 中(按行遍历):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (小矩阵数量 - 2):\n 获取当前小矩阵的最后一列和下一个小矩阵的第一列\n seam_matrix = 合并 当前小矩阵的最后一列 和 下一个小矩阵的第一列(按列合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_cols 中\n\n # 第三拆分方法:取相邻行的小矩阵进行垂直拼接\n 初始化 seam_matrices_rows 为一个空列表\n 对于 i 从 0 到 (行的小矩阵数量 - 2):\n 初始化 row_seams 为一个空列表\n 对于 j 从 0 到 (列的小矩阵数量 - 1):\n 获取当前行的小矩阵和下一行的小矩阵\n top_matrix = 当前行的小矩阵[j]\n bottom_matrix = 下一行的小矩阵[j]\n 拼接 top_matrix 的最后一行和 bottom_matrix 的第一行\n seam_matrix = 合并 top_matrix 的最后一行 和 bottom_matrix 的第一行(按行合并)\n 将 seam_matrix 添加到 row_seams 中\n 将 row_seams 添加到 seam_matrices_rows 中\n\n # 将拆分结果存储到对象属性中\n self.small_matrices = small_matrices\n self.seam_matrices_cols = seam_matrices_cols\n self.seam_matrices_rows = seam_matrices_rows\n```\n”。最终的交付形式为可以独立运行的python脚本,捕获用户输入的两个数字作为矩阵的尺寸。\n\n@tab:active 4/5 进一步进行限定\n#### **模块1**\n\n这里上面的提示词有些问题,我没有严格的定义可视化的方式,于是出现了问题。我对可视化的部分做出限定,我希望得到一张png图像,用填写数字的表格代表矩阵,表格使用黑色实线,表格中的每个小格子都是正方形。矩阵被切分的接缝处使用红色粗实线进行区分。\n\n#### **debug**\n\n我在运行这段代码的时候遇到了问题,详细的上下文信息是“ \n```shell\n% python test.py\n```\n\n```python :collapsed-lines=5\nMatrix Splitting Algorithm with Enhanced Visualization\n------------------------------------------------------\nEnter the number of rows and columns (e.g., '8 12'): 80 12\nGenerated matrix of size 80x12.\nRow factor: 4, Column factor: 4\nMatrix split into 20 row-wise submatrices.\nTotal small matrices after horizontal split: 60\nGenerated seam matrices for columns: 20 sets.\nTraceback (most recent call last):\n File \"/Users/hughes/docs/test.py\", line 195, in让我们回到BioOS平台,来到我们的cellrangerTest页面。试试看,找到页面上的"运行参数"选项卡>输入参数>"上传JSON文件",将您的json文件上传。
然后,点击页面上的绿色按钮"开始分析",等待任务完成。
+任务完成后,您可以在分析历史中看到您的任务。点击任务名称,进入任务详情页面。在任务详情页面,您可以查看/下载结果。
在这个示例中,我们需要的文件在 "outs" 文件夹中,让我们逐渐深入文件夹,找到我们需要的文件。
我们需要这里的 $ID_filtered_feature_bc_matrix.h5ad 文件,让我们点击下载。
1. 复制对GPT输入代码风格化的要求
@@ -10,6 +10,8 @@--------->>> 3. 拆分伪代码,分模块实现
本文通过几个例子展示了用GPT敲代码的几个模式,您需要确保您的键盘具有Ctrl键、C键、V键。
@@ -270,7 +272,7 @@-具体的(注意代码块右侧的复制按钮):
+ 1/5 复制2/5 编写伪代码3/5 先主体4/5 进一步进行限定5/5 插入功能点 这里同上
-You are an advanced AI model designed to solve complex programming challenges by applying a combination of sophisticated reasoning techniques. To ensure your code outputs are technically precise, secure, efficient, and well-documented, follow these structured instructions: @@ -659,7 +661,17 @@ if __name__ == "__main__": main()
结语
+
++ +仔细看看下面的代码,这就是你加上o1-mini的能力
+
diff --git a/docs/.vuepress/.temp/pages/notes/onProgress/index.html.js b/docs/.vuepress/.temp/pages/notes/onProgress/index.html.js index fc46b7d8..480c83b4 100644 --- a/docs/.vuepress/.temp/pages/notes/onProgress/index.html.js +++ b/docs/.vuepress/.temp/pages/notes/onProgress/index.html.js @@ -1,5 +1,5 @@ import comp from "/Users/hughes/docs/WDL_Tools_docs/docs/.vuepress/.temp/pages/notes/onProgress/index.html.vue" -const data = JSON.parse("{\"path\":\"/notes/onProgress/\",\"title\":\"onPress\",\"lang\":\"zh-CN\",\"frontmatter\":{\"title\":\"onPress\",\"createTime\":\"2024/11/07 10:35:59\",\"permalink\":\"/notes/onProgress/\",\"gitInclude\":[]},\"headers\":[{\"level\":2,\"title\":\"Sorry, we are still on progress.\",\"slug\":\"sorry-we-are-still-on-progress\",\"link\":\"#sorry-we-are-still-on-progress\",\"children\":[]},{\"level\":2,\"title\":\"正在更新 Still On Progress\",\"slug\":\"正在更新-still-on-progress\",\"link\":\"#正在更新-still-on-progress\",\"children\":[]},{\"level\":2,\"title\":\"视频嵌入\",\"slug\":\"视频嵌入\",\"link\":\"#视频嵌入\",\"children\":[]},{\"level\":2,\"title\":\"标题 2\",\"slug\":\"标题-2\",\"link\":\"#标题-2\",\"children\":[{\"level\":3,\"title\":\"标题 3\",\"slug\":\"标题-3\",\"link\":\"#标题-3\",\"children\":[]}]},{\"level\":2,\"title\":\"online notebook, based on marimo.app\",\"slug\":\"online-notebook-based-on-marimo-app\",\"link\":\"#online-notebook-based-on-marimo-app\",\"children\":[]}],\"readingTime\":{\"minutes\":2.9,\"words\":869},\"filePathRelative\":\"notes/onProgress.md\",\"categoryList\":[{\"id\":\"4358b5\",\"sort\":10001,\"name\":\"notes\"}],\"bulletin\":false}") +const data = JSON.parse("{\"path\":\"/notes/onProgress/\",\"title\":\"onPress\",\"lang\":\"zh-CN\",\"frontmatter\":{\"title\":\"onPress\",\"createTime\":\"2024/11/07 10:35:59\",\"permalink\":\"/notes/onProgress/\",\"gitInclude\":[]},\"headers\":[{\"level\":2,\"title\":\"Sorry, we are still on progress.\",\"slug\":\"sorry-we-are-still-on-progress\",\"link\":\"#sorry-we-are-still-on-progress\",\"children\":[]},{\"level\":2,\"title\":\"正在更新 Still On Progress\",\"slug\":\"正在更新-still-on-progress\",\"link\":\"#正在更新-still-on-progress\",\"children\":[]},{\"level\":2,\"title\":\"视频嵌入\",\"slug\":\"视频嵌入\",\"link\":\"#视频嵌入\",\"children\":[]},{\"level\":2,\"title\":\"标题 2\",\"slug\":\"标题-2\",\"link\":\"#标题-2\",\"children\":[{\"level\":3,\"title\":\"标题 3\",\"slug\":\"标题-3\",\"link\":\"#标题-3\",\"children\":[]}]},{\"level\":2,\"title\":\"online notebook, based on marimo.app\",\"slug\":\"online-notebook-based-on-marimo-app\",\"link\":\"#online-notebook-based-on-marimo-app\",\"children\":[]}],\"readingTime\":{\"minutes\":3,\"words\":900},\"filePathRelative\":\"notes/onProgress.md\",\"categoryList\":[{\"id\":\"4358b5\",\"sort\":10001,\"name\":\"notes\"}],\"bulletin\":false}") export { comp, data } if (import.meta.webpackHot) { diff --git a/docs/.vuepress/.temp/pages/notes/onProgress/index.html.vue b/docs/.vuepress/.temp/pages/notes/onProgress/index.html.vue index 89d62cbe..5ec31ea7 100644 --- a/docs/.vuepress/.temp/pages/notes/onProgress/index.html.vue +++ b/docs/.vuepress/.temp/pages/notes/onProgress/index.html.vue @@ -6,6 +6,14 @@我必须在这里重申 “AI放大了人类的能力边界”,代码的最终结果极大的取决于 “人的思考” 的质量。
colab 嵌入
+代码分组:
-const a = 1
+tab1tab2const a = 1
const b = 2
const c = a + b
@@ -216,7 +224,7 @@
important
代码演示:
-
+
<h1>Hello Word!</h1>
<p><span id="very">非常</span>强大!</p>
@@ -230,12 +238,12 @@
选项卡:
-
+
标题1标题2内容区块
内容区块
注意
-
+
标题1标题2内容区块
内容区块
diff --git a/docs/.vuepress/config.ts b/docs/.vuepress/config.ts
index 48255728..7dc01644 100644
--- a/docs/.vuepress/config.ts
+++ b/docs/.vuepress/config.ts
@@ -3,7 +3,7 @@ import { defineUserConfig } from 'vuepress'
import { plumeTheme } from 'vuepress-theme-plume'
export default defineUserConfig({
- base: '/WDL_Tools_docs/',
+ base: '/',
lang: 'zh-CN',
locales: {
'/': {
diff --git a/docs/notes/01_10X_Genomics/scRNA-seq.md b/docs/notes/01_10X_Genomics/scRNA-seq.md
index 4989200a..57ca953a 100644
--- a/docs/notes/01_10X_Genomics/scRNA-seq.md
+++ b/docs/notes/01_10X_Genomics/scRNA-seq.md
@@ -69,9 +69,10 @@ permalink: /01_10X_Genomics/scRNA-seq/
然后,点击页面上的绿色按钮"开始分析",等待任务完成。
+![图片](./scfig1_gif.gif)